From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764550249540.7990727281234; Tue, 15 Jun 2021 06:42:30 -0700 (PDT) Received: from localhost ([::1]:39536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Kn-00007u-6H for importer2@patchew.org; Tue, 15 Jun 2021 09:42:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9HT-0005Xe-3t for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:03 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]:33327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HR-0002dr-5L for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:02 -0400 Received: by mail-ej1-x62a.google.com with SMTP id g20so22741396ejt.0 for ; Tue, 15 Jun 2021 06:39:00 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.38.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YO7OJP33y0qDOR62cV7LoVmTb5HsjkNb5ft4fsaXMPw=; b=L+3bmWqsALIWpc1LgRFYt324kVfiHNeqSVhd0/KEDrw7/exDD25OI05nV6QDBK0oV0 VeHYmu6HgWxdR31eReqkB1lJO3IHiD+F8kBxoqCgOwKv3awl+11hurhYa0IuioZFaSnK 91yJ1IicatORiRtUm73S/16I+ZRnU0jAzwH8chASf88NCHWkuLn1rwaRLmL6lTVf8jro wf7eHnM4YvWtsoTPO5vyADaJoWLMlv8pEnIa6EpjJZfqNSSh2jQKp3UvVB4NLwNB+wsu auGMqYC9WqawuA4pjmVECul0aKxJ+mDH992LuhAraHjdTRbCby9YaZFHPpsM1xFzXNZE LGpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YO7OJP33y0qDOR62cV7LoVmTb5HsjkNb5ft4fsaXMPw=; b=K6/O775/tbeAJkL4I+0QbdUhlTXr0MFQYQCzvJbSZf+gEgOo7waXaPWw5VKWostsHC LxQPxuVda9r4qTgua3SHl7t7aJvyFIor4zBIzj/fs8KWzCro7Y87CmOgQqtonrYvelGX rb0Css0EdVcxs+aMQP0KLlyjej3E+wr7nX+KfV1OcIhv0W07MYV1JMybRt7Thb5Mhbjx SJg57hihkMTbQzRGbxnXaiC7ti0q1YwMCI/dGyF5tODo+dGfD/spCijYp8Q/xh884Nzw 7VsoAypV1MiF+gWtRMEde5bZP+id/IdO78owYB3MGU/WnLZMyJoZGKrQsq1+oVS0mK2E F1pQ== X-Gm-Message-State: AOAM533NkT+LeNUHaNWBFLdbAtTxFbx4Ij/8utulw4Unx7WwV6CtdY0o o+JNlQXfnXKKfydYN7bWoiUDJV+AEcU= X-Google-Smtp-Source: ABdhPJyZmDETsYhPTcfrtD6Cv/MRHhCmf4MVtADi7hMZazrKeF9kzhtKsl4O1rmMd+KKaU/+FX4+1g== X-Received: by 2002:a17:906:670c:: with SMTP id a12mr11795183ejp.249.1623764338274; Tue, 15 Jun 2021 06:38:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 01/33] vnc: avoid deprecation warnings for SASL on OS X Date: Tue, 15 Jun 2021 15:38:23 +0200 Message-Id: <20210615133855.775687-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Apple has deprecated sasl.h functions in OS X 10.11. Therefore, all files that use SASL API need to disable -Wdeprecated-declarations. Remove the only use that is outside vnc-auth-sasl.c and add the relevant #pragma GCC diagnostic there. Signed-off-by: Paolo Bonzini Message-Id: <20210604120915.286195-1-pbonzini@redhat.com> Signed-off-by: Paolo Bonzini --- ui/vnc-auth-sasl.c | 20 ++++++++++++++++++++ ui/vnc-auth-sasl.h | 1 + ui/vnc.c | 10 ++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ui/vnc-auth-sasl.c b/ui/vnc-auth-sasl.c index df7dc08e9f..47fdae5b21 100644 --- a/ui/vnc-auth-sasl.c +++ b/ui/vnc-auth-sasl.c @@ -28,10 +28,30 @@ #include "vnc.h" #include "trace.h" =20 +/* + * Apple has deprecated sasl.h functions in OS X 10.11. Therefore, + * files that use SASL API need to disable -Wdeprecated-declarations. + */ +#ifdef CONFIG_DARWIN +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + /* Max amount of data we send/recv for SASL steps to prevent DOS */ #define SASL_DATA_MAX_LEN (1024 * 1024) =20 =20 +bool vnc_sasl_server_init(Error **errp) +{ + int saslErr =3D sasl_server_init(NULL, "qemu"); + + if (saslErr !=3D SASL_OK) { + error_setg(errp, "Failed to initialize SASL auth: %s", + sasl_errstring(saslErr, NULL, NULL)); + return false; + } + return true; +} + void vnc_sasl_client_cleanup(VncState *vs) { if (vs->sasl.conn) { diff --git a/ui/vnc-auth-sasl.h b/ui/vnc-auth-sasl.h index 1bfb86c6f5..367b8672cc 100644 --- a/ui/vnc-auth-sasl.h +++ b/ui/vnc-auth-sasl.h @@ -63,6 +63,7 @@ struct VncDisplaySASL { char *authzid; }; =20 +bool vnc_sasl_server_init(Error **errp); void vnc_sasl_client_cleanup(VncState *vs); =20 size_t vnc_client_read_sasl(VncState *vs); diff --git a/ui/vnc.c b/ui/vnc.c index b3d4d7b9a5..f0a1550d58 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -4154,14 +4154,8 @@ void vnc_display_open(const char *id, Error **errp) trace_vnc_auth_init(vd, 1, vd->ws_auth, vd->ws_subauth); =20 #ifdef CONFIG_VNC_SASL - if (sasl) { - int saslErr =3D sasl_server_init(NULL, "qemu"); - - if (saslErr !=3D SASL_OK) { - error_setg(errp, "Failed to initialize SASL auth: %s", - sasl_errstring(saslErr, NULL, NULL)); - goto fail; - } + if (sasl && !vnc_sasl_server_init(errp)) { + goto fail; } #endif vd->lock_key_sync =3D lock_key_sync; --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764877413896.7428988602896; Tue, 15 Jun 2021 06:47:57 -0700 (PDT) Received: from localhost ([::1]:56600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Q4-0003BG-8m for importer2@patchew.org; Tue, 15 Jun 2021 09:47:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9HV-0005a3-Vg; Tue, 15 Jun 2021 09:39:06 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:41612) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HR-0002dt-Fy; Tue, 15 Jun 2021 09:39:04 -0400 Received: by mail-ed1-x52c.google.com with SMTP id g18so49204251edq.8; Tue, 15 Jun 2021 06:38:59 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.38.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R0+AwUXW3F+3xw6jgijJ3i774wGZg+ICftnnBWgQ9fA=; b=WfsFJRmf3+VuyUzEpDSJarWNd1b0V/URlXFjxVRA7tT/WdN2Nbtp7tQ2phAHTYT22r 8o5SI3lDAWSoffhzKsFQhUm0qtbopbVrVbyjKare5hwOd3wjRSlDQ+1uUf7By8mvrDig p/lINyyL4mniYGFvHimTQjU1YcN0cgtoHBdgpK2xDLXxzlFIOpe3AIRY5S5DqMn/APWQ BF99r6ZhAb5J4BO780isMdhfUfFD4pVKFkBOEHXLLLzuyMuODhtT5CKjLuOC6Dw3PUqD smDBW+bPePwnjJNmcMQmIxxHe2gqMsrZMYd5f305UBx1YBWsp5ofKeoiyQsaU1F6AnrD 70mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=R0+AwUXW3F+3xw6jgijJ3i774wGZg+ICftnnBWgQ9fA=; b=fGm8pPP8TGNSGYU+DVmcPalgskHlE09o9YwNrBFFNMdq+NBhqRS1Nc/dWou/bF50Hp a6z9z/ssv2QqWSTykLPAUr26KFeTHi8xKU+eDpGIbIrKDR0p1t290NKzXZ1Nq/Rd3IG7 cAj0SUtPrUHfYak6aS/MbEux8zLZHclI0uO1AB4E+Zdvg9b6YYFT0To9qlzbFFSyOvlA nryMDSmsAsziGAaw4+WKpy967oifT8fDlyvbWBwkgRJ5Msw5KEOT16cDm0mdBvL4QR/X wUTGpWeJ+xwxZRCuTGI7It7VIUb+tF7uDs6t06d5ctOa4d9CAQyBI+BprZp/BXldwD8a E6sA== X-Gm-Message-State: AOAM532je/FJrq28AUBMU8t9IMk9Wp12xIGG9GTu0H0jcmqbBBjKC4gO bwOtusuyaHecyZxs3O059knM6CO/nKI= X-Google-Smtp-Source: ABdhPJxq3YtMfBfhv27m8tuqzhEw130RrQg6heHCS0nzfEXvPnjxKOJfYa2iochWEdyiyhXJqhHv3w== X-Received: by 2002:a05:6402:358d:: with SMTP id y13mr3311174edc.264.1623764339009; Tue, 15 Jun 2021 06:38:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/33] vl: Fix an assert failure in error path Date: Tue, 15 Jun 2021 15:38:24 +0200 Message-Id: <20210615133855.775687-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhenzhong Duan , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Zhenzhong Duan Based on the description of error_setg(), the local variable err in qemu_maybe_daemonize() should be initialized to NULL. Without fix, the uninitialized *errp triggers assert failure which doesn't show much valuable information. Before the fix: qemu-system-x86_64: ../util/error.c:59: error_setv: Assertion `*errp =3D=3D= NULL' failed. After fix: qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permissio= n denied Signed-off-by: Zhenzhong Duan Message-Id: <20210610084741.456260-1-zhenzhong.duan@intel.com> Cc: qemu-stable@nongnu.org Fixes: 0546c0609c ("vl: split various early command line options to a separ= ate function", 2020-12-10) Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 326c1e9080..feb4d201f3 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2522,7 +2522,7 @@ static void qemu_process_help_options(void) =20 static void qemu_maybe_daemonize(const char *pid_file) { - Error *err; + Error *err =3D NULL; =20 os_daemonize(); rcu_disable_atfork(); --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764878914305.5504447018079; Tue, 15 Jun 2021 06:47:58 -0700 (PDT) Received: from localhost ([::1]:56656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Q5-0003DR-Lk for importer2@patchew.org; Tue, 15 Jun 2021 09:47:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9HV-0005a1-Uk; Tue, 15 Jun 2021 09:39:05 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:38815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HR-0002eM-Fy; Tue, 15 Jun 2021 09:39:03 -0400 Received: by mail-ed1-x52f.google.com with SMTP id t7so5973316edd.5; Tue, 15 Jun 2021 06:39:00 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:38:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DClC4N0hOztFtxZU3fiXh86K8OwDPTmIEleNDEV+GRg=; b=O7S119gFZP+sEGMdLHbhWlgfVY2hwOWxXzFWBywBqPuy/zTs++791AwysbVa+vJzfM QOqDjZdBSwDFXkCZxas/Osj/KLJnHxsUgO+mJzU2ZWuoczwUMDk2Kk1XLQXbjfx6msh4 4eNrTkwu/Q+57JYzLa0EA/8jGxqsVOPV648iJgPSV8foIV0gwGDmBjNYC+DSO5a9q542 T+z8xwsfkXQ+6sX9mmntVWceinqSon6ILl7bCCJh+uw6jIFcxgRM3c/+91Taue9By7sQ CEg/+wG8Ktbu1NixsUlGsSbST1Zy4HPkllQdsr9OtVyQ37sDg52AlXR1jt7PXjagscbu xZgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=DClC4N0hOztFtxZU3fiXh86K8OwDPTmIEleNDEV+GRg=; b=nq9u37JrULasaieChwnUg5xmh/9B+PQHSggEcZooS704wHluKTPTQiG+2TitVbWGZB lZPGpZDQbB5bLr3DVpy0FmkjhAiZ0tKFDscxva1eMkj+53v3WqD+BoVJYc9xyPYcI2QN MemTdb15URIN+xXea9BlMrhyOnVyItLI3AAr71TqbU4KrfhshcJyCBkPhy8v6tlwOXoW usxDqs0qpjw9pG0bW1zENe+MNr2M8iL2D65J1m3Lv7x0tMPEb4b5JLIL7b/TCzwI4mrE A577fqOGoaNvz5SphMBU96YVWpJjFhI1Xem3EWpv/uw+PXUWqvFWKC6lxYgn8IfK+zMK pOHQ== X-Gm-Message-State: AOAM530wBgqF9WxqaUm6gUQhznXzd/FWeupVsl+NwxmyHU13oIOD9pjd 5ToFny9FbQQ+1W7PILTRdANqpaj/f7o= X-Google-Smtp-Source: ABdhPJyvA0nmNKc9omsMfJPpuLvnEY4UL3eibVU9NtBrqMYfmjlAYIxjz3i8sopn0+kabrJStHttVw== X-Received: by 2002:a05:6402:b17:: with SMTP id bm23mr23148668edb.236.1623764339803; Tue, 15 Jun 2021 06:38:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 03/33] qemu-config: use qemu_opts_from_qdict Date: Tue, 15 Jun 2021 15:38:25 +0200 Message-Id: <20210615133855.775687-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Using qemu_opts_absorb_qdict, and then checking for any leftover options, is redundant because there is already a function that does the same, qemu_opts_from_qdict. qemu_opts_from_qdict consumes the whole dictionary and therefore can just return an error message if an option fails to valida= te. This also fixes a bug, because the "id" entry was retrieved in qemu_config_do_parse and then left there by qemu_opts_absorb_qdict. As a result, it was reported as an unrecognized option. Reported-by: Markus Armbruster Reviewed-by: Markus Armbruster Fixes: 3770141139 ("qemu-config: parse configuration files to a QDict") Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- util/qemu-config.c | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/util/qemu-config.c b/util/qemu-config.c index 374f3bc460..84ee6dc4ea 100644 --- a/util/qemu-config.c +++ b/util/qemu-config.c @@ -429,29 +429,14 @@ out: void qemu_config_do_parse(const char *group, QDict *qdict, void *opaque, E= rror **errp) { QemuOptsList **lists =3D opaque; - const char *id =3D qdict_get_try_str(qdict, "id"); QemuOptsList *list; - QemuOpts *opts; - const QDictEntry *unrecognized; =20 list =3D find_list(lists, group, errp); if (!list) { return; } =20 - opts =3D qemu_opts_create(list, id, 1, errp); - if (!opts) { - return; - } - if (!qemu_opts_absorb_qdict(opts, qdict, errp)) { - qemu_opts_del(opts); - return; - } - unrecognized =3D qdict_first(qdict); - if (unrecognized) { - error_setg(errp, QERR_INVALID_PARAMETER, unrecognized->key); - qemu_opts_del(opts); - } + qemu_opts_from_qdict(list, qdict, errp); } =20 int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, E= rror **errp) --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764698109343.8402661922347; Tue, 15 Jun 2021 06:44:58 -0700 (PDT) Received: from localhost ([::1]:48048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9NB-0005pZ-0L for importer2@patchew.org; Tue, 15 Jun 2021 09:44:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9HV-0005a9-Ve for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:06 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:41617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HS-0002ej-HJ for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:04 -0400 Received: by mail-ed1-x531.google.com with SMTP id g18so49204376edq.8 for ; Tue, 15 Jun 2021 06:39:01 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A7t2qX0fg1RYkfLkBI/P/I/raO7zJCJeZ8mm+rgtgLc=; b=mjYTPHNzZvpUzEftkcPlsqlVnpbU6r0LsnjdCvUoj58V4zCEY1Okq/jesDXnEOB1qB +nifTe68//m9R+lLDqHYUSyosSNOUm6E2r4Znydch4Tv26RSyXY3SO0kfq9ZQELHrMq9 RhTQIlecDvDw7kAzWWTM2MvQVeZy/+SiUu75JCtfJkXoK2lmbicd5xo6kSwd63508FQ+ 7ID/qqSVfh6MZGRxdkkxm0Vx1bS519SMEdiYPYjD8VGSZBvlawdxn48zNV3KOM/S7hTE IlrsVdoY60x69o4mi5n1BYnfmErxPwW6FYX6I+gtpCqyP5pSRdFkprByAZbtcEp6ml94 wUkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=A7t2qX0fg1RYkfLkBI/P/I/raO7zJCJeZ8mm+rgtgLc=; b=BoyvJDfARqlXT3BWX5CFjTol6u1zgzzJkGchzcfuJy5q99CczVJ/2xea8UzpYxOYEB oyAKEgLy9KD1Myi34TvfkNFZQmyPIKILIe2DQfMJWnD3cHxeUzn3rNy+pY0/E3g5yK5+ yBCbl+0Pmt7RZpz9t9N1UzNDvCeKxtxql3jeEZHnsJanQpa7Ov8Y5GWU3KGJ1g1o+WjR khiJEcbcpyLt7MMD5h6JwG7ir/9TWh8FnapXHDOOcz2Dxx2gsFc4v7YDLwtbWiEuM996 Eq9wwHSANb5OFa73RuR3Ley45UgCbpS4rS8fvXmZA0vD9HQvCD6UvfPZviR++iH96zVI jnyA== X-Gm-Message-State: AOAM533aHEyxqNklO83QeYgW6EEH2ELYetyP4H1XqQmkX1T0FtSDDscc paQ5F8Fb0VxNaEGpeWFFhNpzkK9yYj0= X-Google-Smtp-Source: ABdhPJyMQqspfv5a8wg4akg2vaLyxGZ0ptgiI1WgGg38O4gx/BrHtEETpCQBQJaldAcygJMnSFSgPA== X-Received: by 2002:a05:6402:1ac9:: with SMTP id ba9mr23850945edb.250.1623764340490; Tue, 15 Jun 2021 06:39:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 04/33] block/scsi: correctly emulate the VPD block limits page Date: Tue, 15 Jun 2021 15:38:26 +0200 Message-Id: <20210615133855.775687-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x531.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Reitz , Maxim Levitsky Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky When the device doesn't support the VPD block limits page, we emulate it ev= en for SCSI passthrough. As a part of the emulation we need to add it to the 'Supported VPD Pages' The code that does this adds it to the page, but it doesn't increase the le= ngth of the data to be copied to the guest, thus the guest never sees the VPD bl= ock limits page as supported. Bump the transfer size by 1 in this case. Signed-off-by: Maxim Levitsky Reviewed-by: Max Reitz Message-Id: <20201217165612.942849-6-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-generic.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 98c30c5d5c..40e039864f 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -147,7 +147,7 @@ static int execute_command(BlockBackend *blk, return 0; } =20 -static void scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s) +static int scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s, int= len) { uint8_t page, page_idx; =20 @@ -213,8 +213,13 @@ static void scsi_handle_inquiry_reply(SCSIGenericReq *= r, SCSIDevice *s) r->buf[page_idx] =3D 0xb0; } stw_be_p(r->buf + 2, lduw_be_p(r->buf + 2) + 1); + + if (len < r->buflen) { + len++; + } } } + return len; } =20 static int scsi_generic_emulate_block_limits(SCSIGenericReq *r, SCSIDevice= *s) @@ -332,7 +337,7 @@ static void scsi_read_complete(void * opaque, int ret) } } if (r->req.cmd.buf[0] =3D=3D INQUIRY) { - scsi_handle_inquiry_reply(r, s); + len =3D scsi_handle_inquiry_reply(r, s, len); } =20 req_complete: --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764698836714.9249207391109; Tue, 15 Jun 2021 06:44:58 -0700 (PDT) Received: from localhost ([::1]:48042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9NB-0005pJ-Jp for importer2@patchew.org; Tue, 15 Jun 2021 09:44:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9HV-0005Zy-Ts; Tue, 15 Jun 2021 09:39:05 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]:38812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HS-0002ez-TA; Tue, 15 Jun 2021 09:39:04 -0400 Received: by mail-ed1-x52b.google.com with SMTP id t7so5973436edd.5; Tue, 15 Jun 2021 06:39:02 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=heHCUXk2lYlY4womrST8MVwquaQIh6Pc6yFu//DhDE0=; b=QeAucoDTJvp3la0vtvXgglrQd7Kjq7ikSZi6O/Fhbut7WjAfGF2itw64+u85q2lBCQ QYwCncHaKtd2d9t4YlfuoLld5vdkFjZeJ63TtX1dJrCFzo/gu+NfgZTHoCfcF5hdqQlV 71q/8lzS3I1hoMaYWahw0//O0HCv/g3LYCa7zvjmuSVS4DQ3fKJyz7XjjnyKCCMoWQhu ssHcc8B8dG2nO4k2wJ+cs0lpqrXJa8+p90LktKVxJxtwndPhczGlN5JJhvranWpi2vn/ 6ST5QgPuOtP1MX1iHimTMj1JmhaCPzBMr245M/SWFZgpyObk/Mp3aoD+9L5TMn9izNpA jSXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=heHCUXk2lYlY4womrST8MVwquaQIh6Pc6yFu//DhDE0=; b=RRT5oM/2st7SLwTT27tsPRoxlPCQnH36iEiuUonYBagdxI9xYAa5QGkCXHRT5XTFEs gElrAfQWowMsTa1a36PNxsPbTwRiXf7xvQANZrpsBszasGouqWDamohnDGl1eM+507hu nUDqF+UgpgGxLS+A4dhTLcmj1lYqPBDcel5qHVACiBrWDQCNQfrSNr5JBrRm0NYiAPlk HWC747+r2Oe1SWl5nDvbpUFIKzJdjW9hb9+GS27ZC0LqRgMJRu2K1zKXxe/b2uNd+vvA D59nEwRRbu6dWos7wgbi+oL4LyJzIA3KZJSonS/Ll1Eh6B//r4xoXMdTxUgu3qTGztaK C92Q== X-Gm-Message-State: AOAM533ctEiGp2mhiLRhdjHwBAkqxZhATdr3eKIcjQS8XYljPUtrFbYQ DU84CQZFvokmfo7LgRMHSEI0uZWREQQ= X-Google-Smtp-Source: ABdhPJz1Koj3D+JjGoqXOykqQvHnDVhK2vKqaVg7louEg7L9qufyH1kb3AaWx40yQLZCwyv4KlYe/g== X-Received: by 2002:a05:6402:1d0c:: with SMTP id dg12mr23211277edb.155.1623764341245; Tue, 15 Jun 2021 06:39:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/33] runstate: Initialize Error * to NULL Date: Tue, 15 Jun 2021 15:38:27 +0200 Message-Id: <20210615133855.775687-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peng Liang , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Peng Liang Based on the description of error_setg(), the local variable err in qemu_init_subsystems() should be initialized to NULL. Fixes: efd7ab22fb ("vl: extract qemu_init_subsystems") Cc: qemu-stable@nongnu.org Signed-off-by: Peng Liang Message-Id: <20210610131729.3906565-1-liangpeng10@huawei.com> Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Paolo Bonzini --- softmmu/runstate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/softmmu/runstate.c b/softmmu/runstate.c index 15640572c0..10d9b7365a 100644 --- a/softmmu/runstate.c +++ b/softmmu/runstate.c @@ -747,7 +747,7 @@ static void qemu_run_exit_notifiers(void) =20 void qemu_init_subsystems(void) { - Error *err; + Error *err =3D NULL; =20 os_set_line_buffering(); =20 --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765042341784.4668231054577; Tue, 15 Jun 2021 06:50:42 -0700 (PDT) Received: from localhost ([::1]:37910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Sj-00014q-7v for importer2@patchew.org; Tue, 15 Jun 2021 09:50:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9HW-0005aD-1k for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:06 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:40448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HT-0002fb-8a for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:05 -0400 Received: by mail-ej1-x62c.google.com with SMTP id my49so22666471ejc.7 for ; Tue, 15 Jun 2021 06:39:02 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ufg9KAAVUpb6SdQp+JrhzTkawAhYImLq6kgNA9vSLME=; b=sqXAJ12bXyaBGdaVRDkATs7jmtrBnTsRM3dWuz7OzH8gB3mFec6Zx4tOcwSc07SeMf sE4kjY3Z10RgK9Gznqkh2zDVb3fVuMHRF8PnxRwGL0gqa7VWy2wn/FhvReXQsr2FSti/ MW1otputzhYPOwfXDLWBYfAN7U1aEMqQZcE/icXHfz3hpn3+1welq0sTwheGiVfj8QQ1 ic3j374cZtIBO1atD3fcTc2xpS4kNyCjRyooKVeDNrlGuNYKYV2Czsn10qxQkyzt+KRl cJL4ShW5tWQclSjHTHHG2nV6/FKg1S6R3tjQqIruF8kdYwTfuaQ0PfEMdZPyatssrqdp oLsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ufg9KAAVUpb6SdQp+JrhzTkawAhYImLq6kgNA9vSLME=; b=GXQok4c3PInDBjjT6EgoqM4bOIQxTSVXMnF3N/enNItbPs1A2ZE5aywlqokflB1Bn/ 1nboX4OgoRPt+8sfj4gzuG4jBuKiQBbKZ00htsbeuKwilgESUMtsjwTScWKHJQIgGqiB owfpBW9a+0LoXK40zTdwrg6Sb2wqkML4DWflH2DglgoBxtF6dsBdpSAfN9Skcql7J179 PKY4Gg0mzBBFmQCPcAnI92k6/jIMcivnXuehoT9qmhwJi4ueiJ+nfV7rw9v/Emrh85ZN bN5vKcwaOUkMw7L7wwkGokgN5rvYhqml0BMaKEtbSmWmAvb5yNr1QNP2QiMUL6rJuTN3 ABJg== X-Gm-Message-State: AOAM533gZLopPUP0n8YETVCBtM+FJC7rpB/2zptY1B5cgJ1FOt3jZfag Cv8E3C4bVCmTCH+03kAgM9v/tc+MNrY= X-Google-Smtp-Source: ABdhPJw9hT52j2gxlH0A9VInOuQ7o9KXwMnG4muaGPWdikdIK8k+vVOm9l7U3DOvBEfHHF0ImcGhng== X-Received: by 2002:a17:906:7203:: with SMTP id m3mr20597279ejk.381.1623764341952; Tue, 15 Jun 2021 06:39:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/33] esp: only assert INTR_DC interrupt flag if selection fails Date: Tue, 15 Jun 2021 15:38:28 +0200 Message-Id: <20210615133855.775687-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland The datasheet sequence tables confirm that when a target selection fails, o= nly the INTR_DC interrupt flag should be asserted. Signed-off-by: Mark Cave-Ayland Fixes: cf47a41e05 ("esp: latch individual bits in ESP_RINTR register") Message-Id: <20210518212511.21688-2-mark.cave-ayland@ilande.co.uk> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index b668acef82..000e45a624 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -213,7 +213,7 @@ static int esp_select(ESPState *s) if (!s->current_dev) { /* No such drive */ s->rregs[ESP_RSTAT] =3D 0; - s->rregs[ESP_RINTR] |=3D INTR_DC; + s->rregs[ESP_RINTR] =3D INTR_DC; s->rregs[ESP_RSEQ] =3D SEQ_0; esp_raise_irq(s); return -1; --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765028820138.91549822997604; Tue, 15 Jun 2021 06:50:28 -0700 (PDT) Received: from localhost ([::1]:36970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9SU-0000Sd-2e for importer2@patchew.org; Tue, 15 Jun 2021 09:50:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hb-0005e3-1S for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:11 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]:36673) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HU-0002g6-9T for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:07 -0400 Received: by mail-ej1-x629.google.com with SMTP id nd37so14903507ejc.3 for ; Tue, 15 Jun 2021 06:39:03 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f14dpNn0/J+5dS2KxNQSZZBoi/TEgJbxNaHvHTAG8hM=; b=q9f6QEGOAe5dUT8ismLN81WkjxLIsCAzJkY/s/1ihKgVhv9dLjYHGGFZu609AQYqym oBZA3iYPnz8A/Rx6ungK6Ccb2DG7zUMWjUf2b524lqO1lBhL/XYhnr7ybEkKiBVOUvyx 9EUDQWzdjcrZA1Q4vumViqq9QpiqvPQl23rSXOQOdKW/Pv2Ksx8zFE/ApjBnXOSX1CUs yJEKyLgyxyHIjg1d3B5BdVtD+bRmHk17sJykqxjp9U8buihbO6S/g0V8RWTmUN9gzKc8 PLnJb9e+5FSJl2ot+46RhnHL34xgSjl6dhjtLb0yEdOOhKzNKXebN9+ZGwwD+WhZfzqo 3DgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=f14dpNn0/J+5dS2KxNQSZZBoi/TEgJbxNaHvHTAG8hM=; b=EKjjUXsbll/E2uzbvd6vQHbzGdLMDeLNc2Rzu4TWiC21Q72V1sD3vcfzwMRdQKhHHt YCNH3VCRcgbLHgmw0v0Rspa7pZSho2rU1GclmlCNEAj+VTqqO4uHzh2samRbPPGcd4sn s+b3Osz9ZOTFG/BbSdR52LSypqRjFcKNyFfINvkW8flnQ0ro5t8P1aas69bgZqyAg5o4 KKFNIu/2AcWQCY8FGviAmRBNKJV8XzzGipdAdwltj0lYoJZlIzcJ2ZTGOBHib79j/OT7 Ap7AiEtvs0rIqpO6O9JIi6Lt8sNRqfmCPzMDZiN++IhfCvSMgLDmx5tQkFJn3XZxU9o+ ZrBw== X-Gm-Message-State: AOAM532PACldgYklQetJ0feW0HO0hmrL+EgfvyCLgfuFVymUAF4GF6/A WKhhrI9iUEB3lLhuJMb2z4L7swMRP6s= X-Google-Smtp-Source: ABdhPJz1lSAD3Ts/+py85pv8OII5/WBREiLCGMg2tr97K7av9XQwMN6IK42Op45RtGnqKGmiMf9/Lg== X-Received: by 2002:a17:907:7b9d:: with SMTP id ne29mr21513077ejc.167.1623764342613; Tue, 15 Jun 2021 06:39:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/33] esp: only set ESP_RSEQ at the start of the select sequence Date: Tue, 15 Jun 2021 15:38:29 +0200 Message-Id: <20210615133855.775687-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x629.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland When processing a command to select a target and send a CDB, the ESP device maintains a sequence step register so that if an error occurs the host can determine which part of the selection/CDB submission sequence failed. The old Linux 2.6 driver is really pedantic here: it checks the sequence st= ep register even if a command succeeds and complains loudly on the console if = the sequence step register doesn't match the expected bus phase and interrupt f= lags. This reason this mismatch occurs is because the ESP emulation currently doe= sn't update the bus phase until the next TI (Transfer Information) command and s= o the cleared sequence step register is considered invalid for the stale bus phas= e. Normally this isn't an issue as the host only checks the sequence step regi= ster if an error occurs but the old Linux 2.6 driver does this in several places causing a large stream of "esp0: STEP_ASEL for tgt 0" messages to appear on= the console during the boot process. Fix this by not clearing the sequence step register when reading the interr= upt register and clearing the DMA status, so the guest sees a valid sequence st= ep and bus phase combination at the end of the command phase. No other change = is required since the sequence step register is correctly updated throughout t= he selection/CDB submission sequence once one of the select commands is issued. Signed-off-by: Mark Cave-Ayland Fixes: 1b9e48a5bd ("esp: implement non-DMA transfers in PDMA mode") Message-Id: <20210518212511.21688-3-mark.cave-ayland@ilande.co.uk> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 000e45a624..18d4d56392 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -481,7 +481,6 @@ static void esp_dma_done(ESPState *s) { s->rregs[ESP_RSTAT] |=3D STAT_TC; s->rregs[ESP_RINTR] |=3D INTR_BS; - s->rregs[ESP_RSEQ] =3D 0; s->rregs[ESP_RFLAGS] =3D 0; esp_set_tc(s, 0); esp_raise_irq(s); @@ -917,7 +916,15 @@ uint64_t esp_reg_read(ESPState *s, uint32_t saddr) val =3D s->rregs[ESP_RINTR]; s->rregs[ESP_RINTR] =3D 0; s->rregs[ESP_RSTAT] &=3D ~STAT_TC; - s->rregs[ESP_RSEQ] =3D SEQ_0; + /* + * According to the datasheet ESP_RSEQ should be cleared, but as t= he + * emulation currently defers information transfers to the next TI + * command leave it for now so that pedantic guests such as the old + * Linux 2.6 driver see the correct flags before the next SCSI pha= se + * transition. + * + * s->rregs[ESP_RSEQ] =3D SEQ_0; + */ esp_lower_irq(s); break; case ESP_TCHI: --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764648795805.266141444887; Tue, 15 Jun 2021 06:44:08 -0700 (PDT) Received: from localhost ([::1]:44232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9MN-0003HR-Nk for importer2@patchew.org; Tue, 15 Jun 2021 09:44:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hb-0005e9-2Z for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:11 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:37458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HV-0002gj-Mm for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:07 -0400 Received: by mail-ed1-x52c.google.com with SMTP id b11so51176820edy.4 for ; Tue, 15 Jun 2021 06:39:04 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IKk9+G0JEQnt6nXX/qpy3huhzLZsQaa35Rc3qQcIYb0=; b=EeOpl5pNmk3suKsuF1NIA78T87rAdQrDROe3aNOL29oN9Djn99kGOleVD686CYRQlo R27HLb7Yru4pXnmM5XMw88giqN29AXVTZ4OEOEp1dfDSPZ7iv8XGV4IVd0hx+ikLxTUr 52dtHSK3wtU/W0/LEtKxYot+uIsneQnmKq36vxAcPnHXgfHjHkVPPdqwChNdMb3ct6LX ZWyc/hhYAfMwsXME0IQWXRM40vzDVP1y/WQL05a+scUy+h3RwkXZCcfb4wpDxxW2bNPc NSOqYU6U0/YoAkrGfqzlNp6xWGezI/bo3qDyvQLOW6mWq88hG1QCaE007hSpdIOd6HU1 +tUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=IKk9+G0JEQnt6nXX/qpy3huhzLZsQaa35Rc3qQcIYb0=; b=A+6LDl3rKFDZ/M/P8KeM2ZnDwQEYXZZ0eMP1L3CUEliXWmqUazY/RKaDDd1l3KaA2n 3paVqZNxjx4CxE9GsY9NQqIsYa9g8NaVGomlWhrxUdNCaWs6EF3AMWDadPFBz1FMlV1c wqDQAwkBpZGzhK+cHQeBqKK4NMUHy7UKHVFpvtPah+OjhnxiSSXMIuQNBAO1PaRGoZbn TEnlDHCJrC/QJGLrv/JMmdn4ykwKZY2uVqO0fYa6jMMWGOIkx8JZyrUuaA48vZaZyDj5 G5Y773o4Pl4EP4oRBC1QbONKccgSt4Sj2Ga/ojjYoBrN0LOtVu4mU7blpKMWRmA6foc1 Tz2g== X-Gm-Message-State: AOAM532lu/qyQYxq2mcNKGd0yOxEK0cD4Y9alWez4qMZdx/NdDOwm33w ATt7UDUnrP5CyRZXZoIcphkH/PDu4t0= X-Google-Smtp-Source: ABdhPJyXKNWTTZIRhbWSxHb/VHkid6hsppElt0wHB3U8yELLT9wNrpf7i0sEzcX2vuXaM03RtxV2iQ== X-Received: by 2002:a05:6402:13d7:: with SMTP id a23mr23160068edx.120.1623764343331; Tue, 15 Jun 2021 06:39:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/33] esp: allow non-DMA callback in esp_transfer_data() initial transfer Date: Tue, 15 Jun 2021 15:38:30 +0200 Message-Id: <20210615133855.775687-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland The current implementation only resumes DMA transfers when incoming data is received from the target device, but this is also required for non-DMA tran= sfers with the next set of non-DMA changes. Rather than duplicate the DMA/non-DMA dispatch logic in the initial transfer section, update the code so that the initial transfer section can just fallthrough to the main DMA/non-DMA dispatch logic. Signed-off-by: Mark Cave-Ayland Message-Id: <20210519100803.10293-2-mark.cave-ayland@ilande.co.uk> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 18d4d56392..50757e9264 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -803,16 +803,6 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len) s->rregs[ESP_RSTAT] |=3D STAT_TC; s->rregs[ESP_RINTR] |=3D INTR_BS; esp_raise_irq(s); - - /* - * If data is ready to transfer and the TI command has already - * been executed, start DMA immediately. Otherwise DMA will start - * when host sends the TI command - */ - if (s->ti_size && (s->rregs[ESP_CMD] =3D=3D (CMD_TI | CMD_DMA))) { - esp_do_dma(s); - } - return; } =20 if (s->ti_cmd =3D=3D 0) { @@ -826,7 +816,7 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len) return; } =20 - if (s->ti_cmd & CMD_DMA) { + if (s->ti_cmd =3D=3D (CMD_TI | CMD_DMA)) { if (dmalen) { esp_do_dma(s); } else if (s->ti_size <=3D 0) { @@ -837,7 +827,7 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len) esp_dma_done(s); esp_lower_drq(s); } - } else { + } else if (s->ti_cmd =3D=3D CMD_TI) { esp_do_nodma(s); } } --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764581069288.03158324400283; Tue, 15 Jun 2021 06:43:01 -0700 (PDT) Received: from localhost ([::1]:40768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9LH-0000yI-Dm for importer2@patchew.org; Tue, 15 Jun 2021 09:42:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hb-0005e1-1R for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:11 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:38823) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9HV-0002gt-Nl for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:07 -0400 Received: by mail-ed1-x536.google.com with SMTP id t7so5973645edd.5 for ; Tue, 15 Jun 2021 06:39:04 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=52yK9tDksrAnMSuBE9k75TLafvWVHLG9kcmE/+mL6v8=; b=k16ZrRDY89wZpfPBjRQfJr5fMQIoVQGqw74R/gbXVxnCCJpDShiA/EwakZO6pjMDxv FQ2Zeh4EyyCOiflgnOdA4bibh4+JLLKkW3yLs6onD5W4qspHAYzqD3sBZZKzIfH8uR/i /foMzd1+kyrFxkExWUXyt2r9mDrYNIhp/vp1r4FBfqCL06KYlWIY6wiVZnuv1ei/fQm7 illSx6J7gXa1+C7b0k6YUcRWzWtwYcRStT4Sfa/MtlouxlJxofy4C+9uvSZT6WMPx8uA xwx3nEcb5qduIXLZx6UNTo3POiPfihztMWeQ37OjrUxkrs3rTICDLP+XMB4K8ejfvyFy +m5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=52yK9tDksrAnMSuBE9k75TLafvWVHLG9kcmE/+mL6v8=; b=Q1jJqX9FtYgwppiVGAJcd+JNkXj/pTIJTiH//bDi6vdWmAnjNbu6CCheUNu5Zd/bOv McSv9PfKqnFGrqQ88ORsrMsUT/iRPNUt7NmbkekMTyEmb18meyF8cW6VXxDxsGFx5EXT +puNEdYuM6UexKyVK+n1kGbb/7POTtUFCNW9JVnqs4g7V2lOoOz1aSbc37MvxTWek2N1 18LY9IB+VAYX6KIoI/eFBFgRk5x9mbjYLldbIhx1KuLdjFx2VAlpWeTPYXnkVo0SIPTt 0eUyUmdQ+5yxXntdCRV2rPF2B+uYhYtxWZFFxTyktxGcRie0xnyOqm5b5gUsFbcnvQK5 /t6A== X-Gm-Message-State: AOAM5337eNhOOgM471eRWlY9fCJt4q/2tWmg8HbQnIYKPen6nD6m39qk i7NS1h/3umNY/miRKVvnoswPzS+C0EE= X-Google-Smtp-Source: ABdhPJxLHkxnwxcGFZ6X4SWgavacD8RIqEWiO/HRDrmFpT5xSzsoSZ9On5NGkNDRfj1XFoZcDdXaOg== X-Received: by 2002:a05:6402:49a:: with SMTP id k26mr23328171edv.279.1623764344017; Tue, 15 Jun 2021 06:39:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 09/33] esp: handle non-DMA transfers from the target one byte at a time Date: Tue, 15 Jun 2021 15:38:31 +0200 Message-Id: <20210615133855.775687-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::536; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x536.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland The initial implementation of non-DMA transfers was based upon analysis of = traces from the MacOS toolbox ROM for handling unaligned reads but missed one key aspect - during a non-DMA transfer from the target, the bus service interru= pt should be raised for every single byte received from the bus and not just a= t either the end of the transfer or when the FIFO is full. Adjust the non-DMA code accordingly so that esp_do_nodma() is called for ev= ery byte received from the target. This also includes special handling for managing = the change from DATA IN to STATUS phase as this needs to occur when the final byte is = read out from the FIFO, and not at the end of the transfer of the last byte into the= FIFO. Signed-off-by: Mark Cave-Ayland Message-Id: <20210519100803.10293-3-mark.cave-ayland@ilande.co.uk> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 72 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 50757e9264..a0dab319f2 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -739,20 +739,17 @@ static void esp_do_nodma(ESPState *s) s->async_len -=3D len; s->ti_size +=3D len; } else { - len =3D MIN(s->ti_size, s->async_len); - len =3D MIN(len, fifo8_num_free(&s->fifo)); - fifo8_push_all(&s->fifo, s->async_buf, len); - s->async_buf +=3D len; - s->async_len -=3D len; - s->ti_size -=3D len; + if (fifo8_is_empty(&s->fifo)) { + fifo8_push(&s->fifo, s->async_buf[0]); + s->async_buf++; + s->async_len--; + s->ti_size--; + } } =20 if (s->async_len =3D=3D 0) { scsi_req_continue(s->current_req); - - if (to_device || s->ti_size =3D=3D 0) { - return; - } + return; } =20 s->rregs[ESP_RINTR] |=3D INTR_BS; @@ -762,20 +759,37 @@ static void esp_do_nodma(ESPState *s) void esp_command_complete(SCSIRequest *req, size_t resid) { ESPState *s =3D req->hba_private; + int to_device =3D ((s->rregs[ESP_RSTAT] & 7) =3D=3D STAT_DO); =20 trace_esp_command_complete(); - if (s->ti_size !=3D 0) { - trace_esp_command_complete_unexpected(); + + /* + * Non-DMA transfers from the target will leave the last byte in + * the FIFO so don't reset ti_size in this case + */ + if (s->dma || to_device) { + if (s->ti_size !=3D 0) { + trace_esp_command_complete_unexpected(); + } + s->ti_size =3D 0; } - s->ti_size =3D 0; + s->async_len =3D 0; if (req->status) { trace_esp_command_complete_fail(); } s->status =3D req->status; - s->rregs[ESP_RSTAT] =3D STAT_ST; - esp_dma_done(s); - esp_lower_drq(s); + + /* + * If the transfer is finished, switch to status phase. For non-DMA + * transfers from the target the last byte is still in the FIFO + */ + if (s->ti_size =3D=3D 0) { + s->rregs[ESP_RSTAT] =3D STAT_TC | STAT_ST; + esp_dma_done(s); + esp_lower_drq(s); + } + if (s->current_req) { scsi_req_unref(s->current_req); s->current_req =3D NULL; @@ -894,6 +908,17 @@ uint64_t esp_reg_read(ESPState *s, uint32_t saddr) qemu_log_mask(LOG_UNIMP, "esp: PIO data read not implemented\n= "); s->rregs[ESP_FIFO] =3D 0; } else { + if ((s->rregs[ESP_RSTAT] & 0x7) =3D=3D STAT_DI) { + if (s->ti_size) { + esp_do_nodma(s); + } else { + /* + * The last byte of a non-DMA transfer has been read o= ut + * of the FIFO so switch to status phase + */ + s->rregs[ESP_RSTAT] =3D STAT_TC | STAT_ST; + } + } s->rregs[ESP_FIFO] =3D esp_fifo_pop(&s->fifo); } val =3D s->rregs[ESP_FIFO]; @@ -952,15 +977,18 @@ void esp_reg_write(ESPState *s, uint32_t saddr, uint6= 4_t val) case ESP_FIFO: if (s->do_cmd) { esp_fifo_push(&s->cmdfifo, val); + + /* + * If any unexpected message out/command phase data is + * transferred using non-DMA, raise the interrupt + */ + if (s->rregs[ESP_CMD] =3D=3D CMD_TI) { + s->rregs[ESP_RINTR] |=3D INTR_BS; + esp_raise_irq(s); + } } else { esp_fifo_push(&s->fifo, val); } - - /* Non-DMA transfers raise an interrupt after every byte */ - if (s->rregs[ESP_CMD] =3D=3D CMD_TI) { - s->rregs[ESP_RINTR] |=3D INTR_FC | INTR_BS; - esp_raise_irq(s); - } break; case ESP_CMD: s->rregs[saddr] =3D val; --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162376517712566.01340047681504; Tue, 15 Jun 2021 06:52:57 -0700 (PDT) Received: from localhost ([::1]:46446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Ut-0006q4-Ul for importer2@patchew.org; Tue, 15 Jun 2021 09:52:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hc-0005hE-Hu for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:12 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:42761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Ha-0002iR-RI for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:12 -0400 Received: by mail-ej1-x630.google.com with SMTP id k25so22660065eja.9 for ; Tue, 15 Jun 2021 06:39:09 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jAqjWDErtnLGwFchY0uK4XqmiFgGys4roy5kdJRxfio=; b=gxOX45+k4t428q89lRvRZoGga2QWxZ+yY7hxk+rVGRDCThlmnE0wc7uH36YAadc9VH tsBaga6GmZ2hM6y/PonpEAkSNXL6ENLTCQAGqCbaIMGKKhrCmY6tQSUp9Ov0xNW8yyk0 si7vdP0g8ZvEpGytN2VubFWtcPYYsdafrldQIzkYKVDSbj8pWHgV9blDlFfuuPCf9Q3K tquegGVmDiE3DuTNDTI/ExEnu56wP3AMpJLljpmETZ/XlZv0DXFhiW3v2i9wFAJBw3ZE YWRVocgJycHKGWj0dq5wGKoLyq2bLJv0zKj1In0b7Rry12V2EgAGP0A6TAZy4SapSs81 9ymg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jAqjWDErtnLGwFchY0uK4XqmiFgGys4roy5kdJRxfio=; b=NzTWx1/AA3qnDa/WRLjRzeTfHp6NTT6DSw++wv9Mv8LEQ5iNTrkqA8By3IM1mo2bAl o3Q3pnQ9eDG9Jsz9qrC/7yTjDS0JAX9x74OyFINFeNi80xZIy6LKkQNBVwEhSmJ64Hab ji2dQAQDcOMqWMRvP37DQcGeeSzZfOFD2GScWyhuqkZT7MFrP7X+Qzmwgjq0GkB6Y3iB qEX1L50co5n7x3L8nRZENZg617verkVXVt3EuhlCk/AW3HU/VjYG9pu43/1vDgZapuy1 bGnJxKgLDgFuaZM45Uw5uN4i7fH34o2pq9R0Yi6Dr/10H43LrH5W5ad9bV+IMeAtU8Xw /6fw== X-Gm-Message-State: AOAM532oo54HhBXyvVCqpWY3J2HKt2rYylur4rGxgAzdSCzzWlK13aPX NW/CxG60Q4C5vkrKDhE2isgTbzczOGM= X-Google-Smtp-Source: ABdhPJyxLAQNHXgTNoUiF74HzQWABrlYZqJvVCbk/KUMwQhXCPaZrvJ4H7J9jTG+GP4xXd5yaSso2A== X-Received: by 2002:a17:907:1b22:: with SMTP id mp34mr2743996ejc.408.1623764344769; Tue, 15 Jun 2021 06:39:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 10/33] esp: ensure PDMA write transfers are flushed from the FIFO to the target immediately Date: Tue, 15 Jun 2021 15:38:32 +0200 Message-Id: <20210615133855.775687-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x630.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland After each PDMA write transfer the MacOS CDROM driver waits until the FIFO = is empty (i.e. its contents have been written out to the SCSI bus) by polling the FI= FO count register until it reads 0. This doesn't work with the current PDMA write implementation which waits until either the FIFO is full or the transfer is= complete before invoking the PDMA callback to process the FIFO contents. Change the PDMA write transfer logic so that the PDMA callback is invoked a= fter each PDMA write to transfer the FIFO contents to the target buffer immediately, = and hence avoid getting stuck in the FIFO count register polling loop. Signed-off-by: Mark Cave-Ayland Message-Id: <20210519100803.10293-4-mark.cave-ayland@ilande.co.uk> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index a0dab319f2..8e314ef156 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -338,9 +338,9 @@ static void do_cmd(ESPState *s) =20 static void satn_pdma_cb(ESPState *s) { - s->do_cmd =3D 0; - if (!fifo8_is_empty(&s->cmdfifo)) { + if (!esp_get_tc(s) && !fifo8_is_empty(&s->cmdfifo)) { s->cmdfifo_cdb_offset =3D 1; + s->do_cmd =3D 0; do_cmd(s); } } @@ -369,12 +369,9 @@ static void handle_satn(ESPState *s) =20 static void s_without_satn_pdma_cb(ESPState *s) { - uint32_t len; - - s->do_cmd =3D 0; - len =3D fifo8_num_used(&s->cmdfifo); - if (len) { + if (!esp_get_tc(s) && !fifo8_is_empty(&s->cmdfifo)) { s->cmdfifo_cdb_offset =3D 0; + s->do_cmd =3D 0; do_busid_cmd(s, 0); } } @@ -403,8 +400,7 @@ static void handle_s_without_atn(ESPState *s) =20 static void satn_stop_pdma_cb(ESPState *s) { - s->do_cmd =3D 0; - if (!fifo8_is_empty(&s->cmdfifo)) { + if (!esp_get_tc(s) && !fifo8_is_empty(&s->cmdfifo)) { trace_esp_handle_satn_stop(fifo8_num_used(&s->cmdfifo)); s->do_cmd =3D 1; s->cmdfifo_cdb_offset =3D 1; @@ -493,6 +489,11 @@ static void do_dma_pdma_cb(ESPState *s) uint32_t n; =20 if (s->do_cmd) { + /* Ensure we have received complete command after SATN and stop */ + if (esp_get_tc(s) || fifo8_is_empty(&s->cmdfifo)) { + return; + } + s->ti_size =3D 0; s->do_cmd =3D 0; do_cmd(s); @@ -1220,7 +1221,6 @@ static void sysbus_esp_pdma_write(void *opaque, hwadd= r addr, { SysBusESPState *sysbus =3D opaque; ESPState *s =3D ESP(&sysbus->esp); - uint32_t dmalen; =20 trace_esp_pdma_write(size); =20 @@ -1233,10 +1233,7 @@ static void sysbus_esp_pdma_write(void *opaque, hwad= dr addr, esp_pdma_write(s, val); break; } - dmalen =3D esp_get_tc(s); - if (dmalen =3D=3D 0 || fifo8_num_free(&s->fifo) < 2) { - s->pdma_cb(s); - } + s->pdma_cb(s); } =20 static uint64_t sysbus_esp_pdma_read(void *opaque, hwaddr addr, --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162376516979033.45397163123687; Tue, 15 Jun 2021 06:52:49 -0700 (PDT) Received: from localhost ([::1]:45630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Um-0006II-ON for importer2@patchew.org; Tue, 15 Jun 2021 09:52:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hc-0005iQ-SI for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:12 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]:42766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Ha-0002iU-Rt for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:12 -0400 Received: by mail-ej1-x635.google.com with SMTP id k25so22660138eja.9 for ; Tue, 15 Jun 2021 06:39:10 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s80JSWWhXUaW8VPewNLASzQ/RLf7bfO/1fOwopy2TkA=; b=AT4IJEwq2pBvMu3BDB/7nTesnDnGgnZ/ZVIu07NoSDvf3jHPsFijrEG/0lJSV8zvmy lAQ002Sdvv3X9Jubznet01Eopqr0Mdx41OY6jukloCj7i0/V+kZQlrokwmLm1H7ScUr8 Rbam2W2TZ+O5IxYrf7YbmwQtO0u3BPo3IUtaFEpa7OuG2X4gsFSEhnzeHkUyNkkdMKKF ltGOFuwwq3O2K8ni1YanfVMDJfz6j77eMQPhyOZv52zHMkbVxqapqQUyvj0eEVFT8lyy Do8CzpfqWvnHpI+0i4NXH6ML9s6w3nDrtM5R3CDq7cIxvr5wV/nGx+NT+Ex2MzKc0/7C PPUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=s80JSWWhXUaW8VPewNLASzQ/RLf7bfO/1fOwopy2TkA=; b=f3rFUQX7tM8ggg4gD2apdcgJvZ6wy0W5S2UHoFP9NwLBfoy1UVmJhvjDRnRCrpP/hG lay2jfOpzdmlaZ6xbBcvzI+Moa8XoVkA4eiZL5WsX86gXfjBvLk6lkDT0LUt8klmqlCk t4bgmqt1E3mcHcjk1jxk/tfZy4y+TzIW3+D+tlKM+wTih0RbJCBcnqIOvQFm5mZAgNP5 2Cy4oEB2iFSbSADDjtRRN3J065U19UTe+w1/Altld4lMt4vSESkqJY8vMW8CkyF0mEOT 7AiykanUrLLR+GCAkIOjYuf5YYEF/doplgyQnUBoWKZTQAaaL5D5zygALEpsMOIDsol4 1Gbw== X-Gm-Message-State: AOAM532/vb1P+kIWe09ILWjbTZLdBEO+jQXLZIOzRu6UXDRWbtYkW1tN V700pRORz1qSZBdDgoPaEGWw1iVxCh4= X-Google-Smtp-Source: ABdhPJzG9uy64aee2FmKytG925AdWVCxXRDPP4bTXEQd//g3cwMUDdVSQA8/zvOOXOjkV7rCsgr2GQ== X-Received: by 2002:a17:906:26db:: with SMTP id u27mr21028839ejc.532.1623764349334; Tue, 15 Jun 2021 06:39:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 11/33] esp: revert 75ef849696 "esp: correctly fill bus id with requested lun" Date: Tue, 15 Jun 2021 15:38:33 +0200 Message-Id: <20210615133855.775687-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::635; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x635.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland This commit from nearly 10 years ago is now broken due to the improvements in esp emulation (or perhaps was never correct). It shows up as a bug in detecting the CDROM drive under MacOS. The error is caused by the MacOS CDROM driver sending this CDB with an "S without ATN" command and without DMA: 0x12 0x00 0x00 0x00 0x05 0x00 (INQUIRY) This is a valid INQUIRY command, however with this logic present the 3rd byte (0x0) is copied over the 1st byte (0x12) which silently converts the INQUIRY command to a TEST UNIT READY command before passing it to the QEMU SCSI layer. Since the TEST UNIT READY command has a zero length response the MacOS CDROM driver never receives a response and assumes the CDROM is not present. The logic was to ignore the IDENTIFY byte and copy the LUN over from the CDB, which did store the LUN in bits 5-7 of the second byte in olden times. This however is all obsolete, so just drop the code. Signed-off-by: Mark Cave-Ayland Message-Id: <20210519100803.10293-5-mark.cave-ayland@ilande.co.uk> [Tweaked commit message. - Paolo] Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 8e314ef156..16e4b7ead6 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -260,9 +260,6 @@ static uint32_t get_cmd(ESPState *s, uint32_t maxlen) return 0; } n =3D esp_fifo_pop_buf(&s->fifo, buf, dmalen); - if (n >=3D 3) { - buf[0] =3D buf[2] >> 5; - } n =3D MIN(fifo8_num_free(&s->cmdfifo), n); fifo8_push_all(&s->cmdfifo, buf, n); } --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764817811216.90852278750367; Tue, 15 Jun 2021 06:46:57 -0700 (PDT) Received: from localhost ([::1]:53474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9P6-0000yv-Oq for importer2@patchew.org; Tue, 15 Jun 2021 09:46:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hd-0005ix-1i for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:13 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:46970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hb-0002ia-CN for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:12 -0400 Received: by mail-ej1-x634.google.com with SMTP id he7so22428951ejc.13 for ; Tue, 15 Jun 2021 06:39:11 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=40tvBB6URa68U82HNrc5Kt1uj3mSzO0kOZWEskGJLok=; b=nu/h5zXrh6+a5aQB/FFKfvgsh/2qbAX+c1t1VM6XlWc9nbLi9rHA/xxWWhQlG+Wzgy fSiPobIIYL1FrEGewE2bf4qh+g8bN9ooJlF54c/U3o2I+JViziLqgQtqNR1+DWCznGvf gieqqyh40o0myxzSRiIc8o4FNc6lGaLo/q2iALOO9WIkqCXq0VzkAJc5AxePHvJpO9bl k/CFiOMz8A4b3I4YLxSZueVoyb1dumBK6qu0QFjuiaybsfM8RhRZmBHxWfSm7vX9Fc4w t1z5wemHN3fokEZeSFRXj1Sp5ea/rPBSWaMjEdnXONn55ctOxN12e+/62YggCYKjNMGb 6b6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=40tvBB6URa68U82HNrc5Kt1uj3mSzO0kOZWEskGJLok=; b=F9rt6znl7jN4l0fcvh6t1+UFV7XOmovJEzvVrrAjGa4PxDrFDBfxaHcDbtbtcThl5O 3GD8TGPGJ817KkED+88lyOrR4uVenwUNrQz58vAjwZUxIWjBa64KvAyOZGcZRlGSGBDa l7ZTDZGk92DvFYsD1a8HVd7aMQG+mXM+yN+hGIGvK5whzCJ5OB1P0XhoMKYIicTSxqJN WV2EmAq7KZIVF1hfC8gRhIlFbYQvcPvEv/tc+0coknOXg4pu130gCRtjjcCh9IaV4+61 CSXl9l3lWA9mJE8AFVkoF6DXf+kvPMIb/wweOVgPgz/vdwlCSGkxln8k2beRVey/gHV5 ZpSA== X-Gm-Message-State: AOAM530G1lgkQqKETnEVoDaZ32Hv6OqAvJ9HAAKmtvGPBcMlTBYgcZtH ZrNmlUPLAzowqoywZj/NmVTdOXH746c= X-Google-Smtp-Source: ABdhPJwSVLyKLJkRLw2dbMsrTPFQAddsFrT61qmdwjxzvidKkjEOE5d8p/KrlL2OFTUGeRsVSSyycg== X-Received: by 2002:a17:907:7b91:: with SMTP id ne17mr21564553ejc.58.1623764349996; Tue, 15 Jun 2021 06:39:09 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 12/33] esp: correctly accumulate extended messages for PDMA Date: Tue, 15 Jun 2021 15:38:34 +0200 Message-Id: <20210615133855.775687-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x634.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland Commit 799d90d818 "esp: transition to message out phase after SATN and stop command" added logic to correctly handle extended messages for DMA requests but not for PDMA requests. Apply the same logic in esp_do_dma() to do_dma_pdma_cb() so that extended messages terminated with a PDMA request are accumulated correctly. This all= ows the ESP device to respond correctly to the SDTR negotiation initiated by the NetBSD ESP driver without causing errors and timeouts on boot. Signed-off-by: Mark Cave-Ayland Message-Id: <20210519100803.10293-6-mark.cave-ayland@ilande.co.uk> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 16e4b7ead6..3e6f4094fc 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -492,9 +492,26 @@ static void do_dma_pdma_cb(ESPState *s) } =20 s->ti_size =3D 0; - s->do_cmd =3D 0; - do_cmd(s); - esp_lower_drq(s); + if ((s->rregs[ESP_RSTAT] & 7) =3D=3D STAT_CD) { + /* No command received */ + if (s->cmdfifo_cdb_offset =3D=3D fifo8_num_used(&s->cmdfifo)) { + return; + } + + /* Command has been received */ + s->do_cmd =3D 0; + do_cmd(s); + } else { + /* + * Extra message out bytes received: update cmdfifo_cdb_offset + * and then switch to commmand phase + */ + s->cmdfifo_cdb_offset =3D fifo8_num_used(&s->cmdfifo); + s->rregs[ESP_RSTAT] =3D STAT_TC | STAT_CD; + s->rregs[ESP_RSEQ] =3D SEQ_CD; + s->rregs[ESP_RINTR] |=3D INTR_BS; + esp_raise_irq(s); + } return; } =20 --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764783012225.82678681003176; Tue, 15 Jun 2021 06:46:23 -0700 (PDT) Received: from localhost ([::1]:52426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9OX-0000I9-Oq for importer2@patchew.org; Tue, 15 Jun 2021 09:46:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hd-0005kj-Kl for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:14 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]:40448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hb-0002jA-Uq for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:13 -0400 Received: by mail-ej1-x629.google.com with SMTP id my49so22667312ejc.7 for ; Tue, 15 Jun 2021 06:39:11 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O8yAiDOeaxKnyfPeM12ZDJuul1W643A7dHP5nn5YjE8=; b=vV6UiTi0RwHsWL9cNKIhG1JRLJoeLBU6PnxrWABwCQoosiq/jBJt5ZjZXXD3jyFk6f oPx1YLjfzYDV3ucSBkWj/NwOoo/bEgyicJiUWJO5ugcZWqWIR2bnn0K4sjufMb1ABI/b 03NEZd6XEUrj6ng5pSAbOHRjXkDgHNAciiFd1A7SdjapSuHEocGECZNZfT7KxvbHGhVv AB+hoHBvEu1dn3Hs/dsZ00VZdtFKoQZm6OjFPz0M0p6dpShl/F7oBN7JgTnkK/dVTykl idz5Ucp56DDZybWw7ItTBRlvynnUdPZPJapD7VLqCUG3edM3SetmyxaNDVRYhD8CgmRm QuNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=O8yAiDOeaxKnyfPeM12ZDJuul1W643A7dHP5nn5YjE8=; b=lDA4eiWtxuedpbkpGdJyBCbnVftnLAEbtiw7P6I+NDCZng0LPXDVxDEEOkaq2GEUcn Xv/7jvN2B5XMp2ykGKt3rvw0na0S5ABrLURxkkrxGhllY/BSeJTLycI4hKtcyi/rSuXj GQa6PWrQDlfOneTsLw8G6kJ9DSG5NEA2bf4NluXRm5LhdPmuhLGvbzMzpN4HNHPfQQ6J vDgD34W7PRouryxZ0cCLQRSzlBPHoEUMBqjeFe9Li6XT58StDfZNFtjcKTPGVaZaJojw LIULJUWNLIHD3qJKE1xy1UtV7t2XSj7CBCY+glRn1G9XJ/Lfcv5Ks7zfbvGdIeWXJRJG /NBA== X-Gm-Message-State: AOAM530VHJuVr23t3kT5XeCBi51lsT5JJDWVW+F+r6EoLcrIwzSAnitm wqIu01xUubltafRvZZP6AxQgeymYi70= X-Google-Smtp-Source: ABdhPJxZP5W7D0UUtOMw9j3WtO3OHXKxXA9webSPnkzPWQ+xZdgMGGyBpHPgy0aTEqtz8TeA72ub3Q== X-Received: by 2002:a17:907:a9c:: with SMTP id by28mr486442ejc.308.1623764350768; Tue, 15 Jun 2021 06:39:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 13/33] esp: fix migration version check in esp_is_version_5() Date: Tue, 15 Jun 2021 15:38:35 +0200 Message-Id: <20210615133855.775687-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x629.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland Commit 4e78f3bf35 "esp: defer command completion interrupt on incoming data transfers" added a version check for use with VMSTATE_*_TEST macros to allow migration from older QEMU versions. Unfortunately the version check fails to work in its current form since if the VMStateDescription version_id is incremented, the test returns false and so the fields are not included in t= he outgoing migration stream. Change the version check to use >=3D rather =3D=3D to ensure that migration= works correctly when the ESPState VMStateDescription has version_id > 5. Signed-off-by: Mark Cave-Ayland Fixes: 4e78f3bf35 ("esp: defer command completion interrupt on incoming dat= a transfers") Message-Id: <20210613102614.5438-1-mark.cave-ayland@ilande.co.uk> Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 3e6f4094fc..8fad87be9d 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -1128,7 +1128,7 @@ static bool esp_is_version_5(void *opaque, int versio= n_id) ESPState *s =3D ESP(opaque); =20 version_id =3D MIN(version_id, s->mig_version_id); - return version_id =3D=3D 5; + return version_id >=3D 5; } =20 int esp_pre_save(void *opaque) --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764951660450.01430342437095; Tue, 15 Jun 2021 06:49:11 -0700 (PDT) Received: from localhost ([::1]:33794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9RG-0006m7-If for importer2@patchew.org; Tue, 15 Jun 2021 09:49:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9He-0005mo-IF for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:14 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]:38695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hc-0002kJ-S6 for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:14 -0400 Received: by mail-ej1-x632.google.com with SMTP id og14so22674223ejc.5 for ; Tue, 15 Jun 2021 06:39:12 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G80CxhJzBDhoAJSgUulDg325vJO9fD6ZEzEYxclyxvY=; b=Amjo16He5pZihC1BDqn2qy2u0aWah4zJEj8aoL+sudKguyl0XD1xFgQWQ2AY7LEBK2 aXgj5cm7+slOha+oyzuikzboBglSqr/0BqzNTHPOyLPjhLZV5qn7PMYj3CRRlHXL4q1S HdJwaDvBXgwrHPJmpvKvo4jiRbhvG381mvT9LlVgYPyGxSv6uELq8a0xxE8vLDttTpMa TfCtTrA0AaDyxmZVxjud7zUxKcSN4qeROAdzjP1AzmD23DiB3PpmYS/BqVoqehmygXAN 7OY2apZdDFSn9pvCOJ05gGZ4PLzMV6bXdHPuAqFKv2QSlo7dpsNSfmf8aGA8v2aDxTSu p8Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=G80CxhJzBDhoAJSgUulDg325vJO9fD6ZEzEYxclyxvY=; b=NK0J/AKmkoDMS2cFskz7Qc3b3azaX44IZI5k2yX4azn7/hMRx09XiH2yteUfEJzK8o mWJq5S080WAI+PjIH70Q29faWIhBRZxaAb58oEGjCuWJ7AMWWJN8w2niUN+uEipxwseb zSd1EZjWJTHfbkDDhQuH+dFpoYU0JWFtlO6oda+fFEEVDD1g8ifWFxEmGncKcuXADV59 bUq4DRw1ERrVMje5ruvWFFN9emSa+/WGh23ZmenPm7XKAd4KV557t/+xoGkjXLHaMSVn ba4LdpJstlAjKqkAg/5WMeV05bn44mi4mShA2jW/2Lt8d4NNfqvGbFiVMdpuW6/wpgLJ DCFA== X-Gm-Message-State: AOAM530CyWtGii7U1e65odvute35DuGa1ae8VbxQD64D3Cw0SzbyaHKh MOUTKq8LV9YoryjgEt8LqMHBGExl2v4= X-Google-Smtp-Source: ABdhPJzRfILg7zjHKUFQBJETU9kJwpBDMByfRkw1teSJJ5BpHfbVtWfBAGI9sUhEtfq58EQgjVCpAw== X-Received: by 2002:a17:906:7c10:: with SMTP id t16mr20073820ejo.204.1623764351522; Tue, 15 Jun 2021 06:39:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 14/33] esp: store lun coming from the MESSAGE OUT phase Date: Tue, 15 Jun 2021 15:38:36 +0200 Message-Id: <20210615133855.775687-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x632.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The LUN is selected with an IDENTIFY message, and persists until the next message out phase. Instead of passing it to do_busid_cmd, store it in ESPState. Because do_cmd can simply skip the message out phase if cmdfifo_cdb_offset is zero, it can now be used for the S without ATN cases as well. Reviewed-by: Mark Cave-Ayland Tested-by: Mark Cave-Ayland Signed-off-by: Paolo Bonzini --- hw/scsi/esp.c | 47 ++++++++++++++++++++++++++++--------------- hw/scsi/trace-events | 3 ++- include/hw/scsi/esp.h | 1 + 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c index 8fad87be9d..4ac2114788 100644 --- a/hw/scsi/esp.c +++ b/hw/scsi/esp.c @@ -221,7 +221,7 @@ static int esp_select(ESPState *s) =20 /* * Note that we deliberately don't raise the IRQ here: this will be do= ne - * either in do_busid_cmd() for DATA OUT transfers or by the deferred + * either in do_command_phase() for DATA OUT transfers or by the defer= red * IRQ mechanism in esp_transfer_data() for DATA IN transfers */ s->rregs[ESP_RINTR] |=3D INTR_FC; @@ -272,24 +272,22 @@ static uint32_t get_cmd(ESPState *s, uint32_t maxlen) return dmalen; } =20 -static void do_busid_cmd(ESPState *s, uint8_t busid) +static void do_command_phase(ESPState *s) { uint32_t cmdlen; int32_t datalen; - int lun; SCSIDevice *current_lun; uint8_t buf[ESP_CMDFIFO_SZ]; =20 - trace_esp_do_busid_cmd(busid); - lun =3D busid & 7; + trace_esp_do_command_phase(s->lun); cmdlen =3D fifo8_num_used(&s->cmdfifo); if (!cmdlen || !s->current_dev) { return; } esp_fifo_pop_buf(&s->cmdfifo, buf, cmdlen); =20 - current_lun =3D scsi_device_find(&s->bus, 0, s->current_dev->id, lun); - s->current_req =3D scsi_req_new(current_lun, 0, lun, buf, s); + current_lun =3D scsi_device_find(&s->bus, 0, s->current_dev->id, s->lu= n); + s->current_req =3D scsi_req_new(current_lun, 0, s->lun, buf, s); datalen =3D scsi_req_enqueue(s->current_req); s->ti_size =3D datalen; fifo8_reset(&s->cmdfifo); @@ -316,21 +314,29 @@ static void do_busid_cmd(ESPState *s, uint8_t busid) } } =20 -static void do_cmd(ESPState *s) +static void do_message_phase(ESPState *s) { - uint8_t busid =3D esp_fifo_pop(&s->cmdfifo); - int len; + if (s->cmdfifo_cdb_offset) { + uint8_t message =3D esp_fifo_pop(&s->cmdfifo); =20 - s->cmdfifo_cdb_offset--; + trace_esp_do_identify(message); + s->lun =3D message & 7; + s->cmdfifo_cdb_offset--; + } =20 /* Ignore extended messages for now */ if (s->cmdfifo_cdb_offset) { - len =3D MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo)); + int len =3D MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo)= ); esp_fifo_pop_buf(&s->cmdfifo, NULL, len); s->cmdfifo_cdb_offset =3D 0; } +} =20 - do_busid_cmd(s, busid); +static void do_cmd(ESPState *s) +{ + do_message_phase(s); + assert(s->cmdfifo_cdb_offset =3D=3D 0); + do_command_phase(s); } =20 static void satn_pdma_cb(ESPState *s) @@ -369,7 +375,7 @@ static void s_without_satn_pdma_cb(ESPState *s) if (!esp_get_tc(s) && !fifo8_is_empty(&s->cmdfifo)) { s->cmdfifo_cdb_offset =3D 0; s->do_cmd =3D 0; - do_busid_cmd(s, 0); + do_cmd(s); } } =20 @@ -386,7 +392,7 @@ static void handle_s_without_atn(ESPState *s) if (cmdlen > 0) { s->cmdfifo_cdb_offset =3D 0; s->do_cmd =3D 0; - do_busid_cmd(s, 0); + do_cmd(s); } else if (cmdlen =3D=3D 0) { s->do_cmd =3D 1; /* Target present, but no cmd yet - switch to command phase */ @@ -1131,6 +1137,14 @@ static bool esp_is_version_5(void *opaque, int versi= on_id) return version_id >=3D 5; } =20 +static bool esp_is_version_6(void *opaque, int version_id) +{ + ESPState *s =3D ESP(opaque); + + version_id =3D MIN(version_id, s->mig_version_id); + return version_id >=3D 6; +} + int esp_pre_save(void *opaque) { ESPState *s =3D ESP(object_resolve_path_component( @@ -1168,7 +1182,7 @@ static int esp_post_load(void *opaque, int version_id) =20 const VMStateDescription vmstate_esp =3D { .name =3D "esp", - .version_id =3D 5, + .version_id =3D 6, .minimum_version_id =3D 3, .post_load =3D esp_post_load, .fields =3D (VMStateField[]) { @@ -1197,6 +1211,7 @@ const VMStateDescription vmstate_esp =3D { VMSTATE_FIFO8_TEST(fifo, ESPState, esp_is_version_5), VMSTATE_FIFO8_TEST(cmdfifo, ESPState, esp_is_version_5), VMSTATE_UINT8_TEST(ti_cmd, ESPState, esp_is_version_5), + VMSTATE_UINT8_TEST(lun, ESPState, esp_is_version_6), VMSTATE_END_OF_LIST() }, }; diff --git a/hw/scsi/trace-events b/hw/scsi/trace-events index 1a27e141ae..92d5b40f89 100644 --- a/hw/scsi/trace-events +++ b/hw/scsi/trace-events @@ -166,7 +166,8 @@ esp_dma_disable(void) "Lower enable" esp_pdma_read(int size) "pDMA read %u bytes" esp_pdma_write(int size) "pDMA write %u bytes" esp_get_cmd(uint32_t dmalen, int target) "len %d target %d" -esp_do_busid_cmd(uint8_t busid) "busid 0x%x" +esp_do_command_phase(uint8_t busid) "busid 0x%x" +esp_do_identify(uint8_t byte) "0x%x" esp_handle_satn_stop(uint32_t cmdlen) "cmdlen %d" esp_write_response(uint32_t status) "Transfer status (status=3D%d)" esp_do_dma(uint32_t cmdlen, uint32_t len) "command len %d + %d" diff --git a/include/hw/scsi/esp.h b/include/hw/scsi/esp.h index aada3680b7..b1ec27612f 100644 --- a/include/hw/scsi/esp.h +++ b/include/hw/scsi/esp.h @@ -37,6 +37,7 @@ struct ESPState { SCSIRequest *current_req; Fifo8 cmdfifo; uint8_t cmdfifo_cdb_offset; + uint8_t lun; uint32_t do_cmd; =20 bool data_in_ready; --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623764941006520.3929484581586; Tue, 15 Jun 2021 06:49:01 -0700 (PDT) Received: from localhost ([::1]:32894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9R5-0006BA-RS for importer2@patchew.org; Tue, 15 Jun 2021 09:48:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hf-0005oS-7M for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:15 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]:36680) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hd-0002kd-Kb for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:14 -0400 Received: by mail-ej1-x62e.google.com with SMTP id nd37so14904379ejc.3 for ; Tue, 15 Jun 2021 06:39:13 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NdoHLlFzwD8m2yrMeCWWQ4lmLVIsMmdxAXvwoIv9UDs=; b=CZJbVotei2YJzLuDS8YcREXuaWPVAqDex+fj/jucgtMAqYo4Pbpz9QXXNylPuXXvzO NRqRO2+BJTp3gXC72QJc3guXILoPeYbvz6NtL/s1m+T8c5ycyrPaqH0BLYIN/C0NHSR8 Y5i5ig/Qfjk3wFs4ufdO9kY4tuT+srghvpBdAGYtwUg9lzL8Pu2jyC/yn1WDgFIJkJJm 00NPKFCxpmOL6pqhJ7S8jfTCadw39pN7qc+lrCzhEaVZS3S9vFfEsw4y+xszpc/wwgAq BwdepD1L29y4YT0VExyJVeNO/fy2adUZdqzcPmkjgEnFcUxNL00uwS9ogL0WXRLFrWeP R1Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NdoHLlFzwD8m2yrMeCWWQ4lmLVIsMmdxAXvwoIv9UDs=; b=eohjYBUO6HC9nnLn9FU+gMHO57wNwsn5yaVUvHwp8Pr9WPUOTtLydDSjq8lqDZIdCh TWHEdCaRM9iRbdMha7mVZWbqnrJ5h3pR9y9Ufno4z7ECaWthioxl0Y7TZtssm02QkFHU eXH3VKLjimA+7k98sc2K185pTpxzoXCw5HAJYV7CPxc4m9ACnkrxbkWtm0ZEiogpL5Yg zphH5xuvE9/K5cSc7aMf49r5u4KF6PB2scX8Zc3ISt0QSbtD6GG3cgA4MVIiwPY2pC4x n14JVKaM0ApAAsc4YCNiXaVg+ouKMwwPQhtvT0itQTyc6RSfs89aNo9NwgIIJ96peDu1 OC/g== X-Gm-Message-State: AOAM531IKDKorFUQdb0ZSlkAONtzHwuB+i6uAiWgQy5QHRL29UasUxzr OxGeeR7hjHU4Ywhyq8h7bvA3WzKO2tA= X-Google-Smtp-Source: ABdhPJzEef0+r6YyRpFwyZKLJ1FGrYevGeT+D/ON3xRJw9dpvq0cC2zoA3OlLhaORoEfkX8zYQ2u2A== X-Received: by 2002:a17:906:b191:: with SMTP id w17mr21429738ejy.10.1623764352310; Tue, 15 Jun 2021 06:39:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 15/33] softmmu/physmem: Mark shared anonymous memory RAM_SHARED Date: Tue, 15 Jun 2021 15:38:37 +0200 Message-Id: <20210615133855.775687-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62e.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Kotrasinski , Richard Henderson , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's drop the "shared" parameter from ram_block_add() and properly store it in the flags of the ram block instead, such that qemu_ram_is_shared() properly succeeds on all ram blocks that were mapped MAP_SHARED. We'll use this information next to fix some cases with shared anonymous memory. Reviewed-by: Igor Kotrasinski Reviewed-by: Richard Henderson Reviewed-by: Peter Xu Signed-off-by: David Hildenbrand Message-Id: <20210406080126.24010-2-david@redhat.com> Signed-off-by: Paolo Bonzini --- softmmu/physmem.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 1c8717684a..b78b30e7ba 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1946,8 +1946,9 @@ static void dirty_memory_extend(ram_addr_t old_ram_si= ze, } } =20 -static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) +static void ram_block_add(RAMBlock *new_block, Error **errp) { + const bool shared =3D qemu_ram_is_shared(new_block); RAMBlock *block; RAMBlock *last_block =3D NULL; ram_addr_t old_ram_size, new_ram_size; @@ -2084,7 +2085,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, return NULL; } =20 - ram_block_add(new_block, &local_err, ram_flags & RAM_SHARED); + ram_block_add(new_block, &local_err); if (local_err) { g_free(new_block); error_propagate(errp, local_err); @@ -2147,10 +2148,13 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, = ram_addr_t max_size, if (host) { new_block->flags |=3D RAM_PREALLOC; } + if (share) { + new_block->flags |=3D RAM_SHARED; + } if (resizeable) { new_block->flags |=3D RAM_RESIZEABLE; } - ram_block_add(new_block, &local_err, share); + ram_block_add(new_block, &local_err); if (local_err) { g_free(new_block); error_propagate(errp, local_err); --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765325912100.54311555177264; Tue, 15 Jun 2021 06:55:25 -0700 (PDT) Received: from localhost ([::1]:54160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9XI-0003Wh-Dt for importer2@patchew.org; Tue, 15 Jun 2021 09:55:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hf-0005qI-Ux for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:15 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:33281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9He-0002lc-DG for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:15 -0400 Received: by mail-ed1-x535.google.com with SMTP id d7so3113915edx.0 for ; Tue, 15 Jun 2021 06:39:14 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2ktS6dUjI6quq2dLhc+A3C2RYRlKl/XKEyMPYSFPo9M=; b=A6LVQoBwgFNfuaPf/MLnr+fFeu4J2sUeOYwihDMq49EB+g2hZtrxJHw0nPwwaOa5dt l24xiq4xNacQnfjLM/TA9BVM062OTLpRnt4MBtWv2e8UZ6Wj1KpipdhC1Ip0mXw2u3xG tg7TQ4krPBJZT2VaKtu2I8Wg4a8sQvfKdVJAtFTDOsnkiW2IbSOE7iqNslSYO+JCs8UI QI+bgq2IBrYjVeIE+pw2qcrrG04YdIZ/L6We+aJhsZEgKhV0JwORExfYxNAi9q471xQc DLtckD8RLXtoTyA0KcC+hlOTdqJCGWLIeepVI26wA9kmNkofWI973FtI3GS5qG+5Mzdt HFHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2ktS6dUjI6quq2dLhc+A3C2RYRlKl/XKEyMPYSFPo9M=; b=pK5Ok0lIjLR6pVcYoHWgZCofQvVILcqOin/V8BeKDc48FdJxsX8EIcDAtvYs2bxMW1 3rks0GZHEcle793FOxsQNnMIwj3wF7o2ED6erkf50gDJYxC5bXmVUX70kqkBU5xXDLhW T/UoJceigr/EqxZZq5luuAm5vDul6Jd4uwVRBePNY0j4dS0WPRMVz1Eivu/xVlorx6a4 gPfohU7+C8S92zTvKD2H/tjy8NODlBQ3tBwDTpkC1BJU8bfqh6AIaQ2m3WvOyrz9engb 0OEwbXVyR1jP0OfY1jZg2A2kpU4qTI1dke2vXHAYHp65fuuNUgdm52xALYLJb2NKnUti 4R4A== X-Gm-Message-State: AOAM530Ly6q5hLUyjPp93PoX/v8gpvTyVgFJ1vxAgMNMkXO9X1ZU8jDh oTqkaBS+E1eG+Q1zSGi+E24iXzXI7o8= X-Google-Smtp-Source: ABdhPJxQqH4X9+ijmeEfBhLYcvz02QEJEZf4gD1wkDZwLrbIhodLAj6WB1irfEPDL/keOThrljv3Hw== X-Received: by 2002:a05:6402:22d0:: with SMTP id dm16mr23168811edb.123.1623764353021; Tue, 15 Jun 2021 06:39:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 16/33] softmmu/physmem: Fix ram_block_discard_range() to handle shared anonymous memory Date: Tue, 15 Jun 2021 15:38:38 +0200 Message-Id: <20210615133855.775687-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x535.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Dr . David Alan Gilbert" , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand We can create shared anonymous memory via "-object memory-backend-ram,share=3Don,..." which is, for example, required by PVRDMA for mremap() to work. Shared anonymous memory is weird, though. Instead of MADV_DONTNEED, we have to use MADV_REMOVE: MADV_DONTNEED will only remove / zap all relevant page table entries of the current process, the backend storage will not get removed, resulting in no reduced memory consumption and a repopulation of previous content on next access. Shared anonymous memory is internally really just shmem, but without a fd exposed. As we cannot use fallocate() without the fd to discard the backing storage, MADV_REMOVE gets the same job done without a fd as documented in "man 2 madvise". Removing backing storage implicitly invalidates all page table entries with relevant mappings - an additional MADV_DONTNEED is not required. Fixes: 06329ccecfa0 ("mem: add share parameter to memory-backend-ram") Reviewed-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Signed-off-by: David Hildenbrand Message-Id: <20210406080126.24010-3-david@redhat.com> Signed-off-by: Paolo Bonzini --- softmmu/physmem.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index b78b30e7ba..b417f9c282 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3527,6 +3527,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t st= art, size_t length) /* The logic here is messy; * madvise DONTNEED fails for hugepages * fallocate works on hugepages and shmem + * shared anonymous memory requires madvise REMOVE */ need_madvise =3D (rb->page_size =3D=3D qemu_host_page_size); need_fallocate =3D rb->fd !=3D -1; @@ -3560,7 +3561,11 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t s= tart, size_t length) * fallocate'd away). */ #if defined(CONFIG_MADVISE) - ret =3D madvise(host_startaddr, length, MADV_DONTNEED); + if (qemu_ram_is_shared(rb) && rb->fd < 0) { + ret =3D madvise(host_startaddr, length, MADV_REMOVE); + } else { + ret =3D madvise(host_startaddr, length, MADV_DONTNEED); + } if (ret) { ret =3D -errno; error_report("ram_block_discard_range: Failed to discard r= ange " --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765431893140.02957893569567; Tue, 15 Jun 2021 06:57:11 -0700 (PDT) Received: from localhost ([::1]:34554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Z0-0000vf-N8 for importer2@patchew.org; Tue, 15 Jun 2021 09:57:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hh-0005to-5Q for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:17 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]:34644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hf-0002mD-L6 for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:16 -0400 Received: by mail-ej1-x62a.google.com with SMTP id g8so22656446ejx.1 for ; Tue, 15 Jun 2021 06:39:15 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VfdzGHWM1V4e3ocZC9Ld1RwC+NetqD/RU7bcXjAcddc=; b=iE4flkm9oxpBzzyPKR6z0u5mLtEAmDJtHvqgYcofQWoZXj+9MJLmfVe3i5z3J4pDdk TnjHW9XELCHqsqBKwM5I7EkjdIxBn6sMM3iHLDB1Gm8fR0zYCjZm/3gvmOpaISZNFkR8 PfT5fRjvLQZ1WCsOcaaImXcfsf3PTpTWqfkPkKHgtZfj+h3o+V2SdJzY7cRM7crsQl/o HIkV2bti2RSHmeImc2v6TbScXYhJUWZ3waKIWMpy3lWuqtCnR68AeWpQ9tNrHbkzr5y+ aWL+17RBLNtZvl9z3nUhYxYILX0B9VvLy1rsq7szjZ7Q6grespohNkh8IHK0mknN42wj D3qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=VfdzGHWM1V4e3ocZC9Ld1RwC+NetqD/RU7bcXjAcddc=; b=QdanTjh1zs1qSf15eGd+Ez4gzaSQHanFO4710zzTMi/z6+mWID6A+Bn0XIDk1P2o2y xVErVd1zCNZDI3LyoCVJQOwnw3BOYp1vBy5QiozES1Lf82cMidOYXFU/4cmsgxt4Z/JX vvQBArA8z0i1ANc6AooGDgl456rdhsYsL4w1pDiM7tIt5nUoijfCtT5sphx45/VeYZTd YGFaVeMVZTZEGHbYQ3IHteSDjl5j822xU5nztxCKkuHdYWfrNEWmA8wrdLPgC3mQ2ohq a7NCyPgKiXSp8W+ANQ2DFvhj0aeXh20eIYJmQDjHQZgT4ceZcEv88T+GFOipDYZSWFli uRSQ== X-Gm-Message-State: AOAM532VGuF5swUMwFoB/VkFnH/RGsvyGk5nED81+EGWAyq2KQD5TMIU E5tvAd87fxCH89rY4/gARFFo6hWAjPI= X-Google-Smtp-Source: ABdhPJzAe6IE75tHSFewqbOXFPcJjhpj9sRkgWy8O5ehVb6izNVYwc7mwG/NX9gNfEK9BolUwHy3Zw== X-Received: by 2002:a17:906:7c4d:: with SMTP id g13mr21052035ejp.216.1623764353778; Tue, 15 Jun 2021 06:39:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 17/33] softmmu/physmem: Fix qemu_ram_remap() to handle shared anonymous memory Date: Tue, 15 Jun 2021 15:38:39 +0200 Message-Id: <20210615133855.775687-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62a.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand RAM_SHARED now also properly indicates shared anonymous memory. Let's check that flag for anonymous memory as well, to restore the proper mapping. Fixes: 06329ccecfa0 ("mem: add share parameter to memory-backend-ram") Reviewed-by: Peter Xu Signed-off-by: David Hildenbrand Message-Id: <20210406080126.24010-4-david@redhat.com> Signed-off-by: Paolo Bonzini --- softmmu/physmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index b417f9c282..2f106d0680 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2243,13 +2243,13 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t len= gth) abort(); } else { flags =3D MAP_FIXED; + flags |=3D block->flags & RAM_SHARED ? + MAP_SHARED : MAP_PRIVATE; if (block->fd >=3D 0) { - flags |=3D (block->flags & RAM_SHARED ? - MAP_SHARED : MAP_PRIVATE); area =3D mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, block->fd, offset); } else { - flags |=3D MAP_PRIVATE | MAP_ANONYMOUS; + flags |=3D MAP_ANONYMOUS; area =3D mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, -1, 0); } --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765104827398.2556502849776; Tue, 15 Jun 2021 06:51:44 -0700 (PDT) Received: from localhost ([::1]:42404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Tj-00045O-GK for importer2@patchew.org; Tue, 15 Jun 2021 09:51:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hi-0005xA-Dk for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:18 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:45758) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hg-0002mf-C3 for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:18 -0400 Received: by mail-ed1-x52f.google.com with SMTP id r7so36751812edv.12 for ; Tue, 15 Jun 2021 06:39:15 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HvPqNCF2sjL2JYw07xiEgb3yfgqupeU2JQK8pZnMZEs=; b=FhglVNInCNyRn/nVMaiOGodQuY3BAKBc6YfNdC0rd/bOxJNiWe59iSat1GgIcS3bGN 0FvCjU6x4X/Jho2i5DZGZm+HgPDbhYAYBi+uK8gK/O8lCFRc6v9d1H3Y8aVzsKbVEP/n 7SFNRjBYTJu9rMf12xl5dcDx/psqPxP4BBd3Ilnv+SwKq9eagYcx/4gPcm80aE0PwVSR qXICKHVV3Ebr9CvlAQb3pqyL6jY7hR2JWY5h0KIyOHh2tRmlGIvDv4n5OOGxrQ1Z+Btk mrXI5YW/Vj9LmuSfR4JjNf3hI35MV04oHgm3P2IdM38L/joA5Sqx8PZkElvohIVeZNoM WY9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=HvPqNCF2sjL2JYw07xiEgb3yfgqupeU2JQK8pZnMZEs=; b=cSp4+sMig4GK86am9/oND10VWLA9A7dN5vV5HdbUqYk25Jd66gOnb93R9N8w+O2z+d eq8H+iNpPRGVUYA1LzeLiAb7AWf/ffPczk7kvoUu6hyfmjJ8sfkCgK7epRyjCMOueOUc Mr0e5HHTB9GDO9/jMysqIuXkqOTBjFbloYO3MKx71AdrsevCAKpuDXPh+QCVqyNMRMxA 8SnrKlwRrEp0nHSRmp+i0VdZui6uFhF7baLnnkc2eZhCyOEmGGlTzeGffSPSyUmtv/Yy 78PzDDdBTJOCXHnnKPbn+uaSblEJh/oTmjEMVkmwsxagD0cVl4jbv8EBV+CiSp8meVny PrtQ== X-Gm-Message-State: AOAM531uJMWMYcWNOJYGkOqmqJHdDq3LW/AorMHis9XRyDDQtJxlR4sJ MAjKzt6oMDvLNiyE11Dsvzdy/ccNIuI= X-Google-Smtp-Source: ABdhPJwqzML7j1cNzHB7lNO5C8JGws5taC9cohfhqFUDDUSjeKhjCwFTfRkSBenTNRwUdI3yCVwQlg== X-Received: by 2002:a05:6402:366:: with SMTP id s6mr23664023edw.209.1623764355113; Tue, 15 Jun 2021 06:39:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 18/33] util/mmap-alloc: Factor out calculation of the pagesize for the guard page Date: Tue, 15 Jun 2021 15:38:40 +0200 Message-Id: <20210615133855.775687-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52f; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52f.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Kotrasinski , Murilo Opsfelder Araujo , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's factor out calculating the size of the guard page and rename the variable to make it clearer that this pagesize only applies to the guard page. Reviewed-by: Peter Xu Acked-by: Murilo Opsfelder Araujo Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Igor Kotrasinski Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-2-david@redhat.com> Signed-off-by: Paolo Bonzini --- util/mmap-alloc.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index e6fa8b598b..24854064b4 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -82,6 +82,16 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return qemu_real_host_page_size; } =20 +static inline size_t mmap_guard_pagesize(int fd) +{ +#if defined(__powerpc64__) && defined(__linux__) + /* Mappings in the same segment must share the same page size */ + return qemu_fd_getpagesize(fd); +#else + return qemu_real_host_page_size; +#endif +} + void *qemu_ram_mmap(int fd, size_t size, size_t align, @@ -90,12 +100,12 @@ void *qemu_ram_mmap(int fd, bool is_pmem, off_t map_offset) { + const size_t guard_pagesize =3D mmap_guard_pagesize(fd); int prot; int flags; int map_sync_flags =3D 0; int guardfd; size_t offset; - size_t pagesize; size_t total; void *guardptr; void *ptr; @@ -116,8 +126,7 @@ void *qemu_ram_mmap(int fd, * anonymous memory is OK. */ flags =3D MAP_PRIVATE; - pagesize =3D qemu_fd_getpagesize(fd); - if (fd =3D=3D -1 || pagesize =3D=3D qemu_real_host_page_size) { + if (fd =3D=3D -1 || guard_pagesize =3D=3D qemu_real_host_page_size) { guardfd =3D -1; flags |=3D MAP_ANONYMOUS; } else { @@ -126,7 +135,6 @@ void *qemu_ram_mmap(int fd, } #else guardfd =3D -1; - pagesize =3D qemu_real_host_page_size; flags =3D MAP_PRIVATE | MAP_ANONYMOUS; #endif =20 @@ -138,7 +146,7 @@ void *qemu_ram_mmap(int fd, =20 assert(is_power_of_2(align)); /* Always align to host page size */ - assert(align >=3D pagesize); + assert(align >=3D guard_pagesize); =20 flags =3D MAP_FIXED; flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; @@ -193,8 +201,8 @@ void *qemu_ram_mmap(int fd, * a guard page guarding against potential buffer overflows. */ total -=3D offset; - if (total > size + pagesize) { - munmap(ptr + size + pagesize, total - size - pagesize); + if (total > size + guard_pagesize) { + munmap(ptr + size + guard_pagesize, total - size - guard_pagesize); } =20 return ptr; @@ -202,15 +210,8 @@ void *qemu_ram_mmap(int fd, =20 void qemu_ram_munmap(int fd, void *ptr, size_t size) { - size_t pagesize; - if (ptr) { /* Unmap both the RAM block and the guard page */ -#if defined(__powerpc64__) && defined(__linux__) - pagesize =3D qemu_fd_getpagesize(fd); -#else - pagesize =3D qemu_real_host_page_size; -#endif - munmap(ptr, size + pagesize); + munmap(ptr, size + mmap_guard_pagesize(fd)); } } --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765082572497.32753644580373; Tue, 15 Jun 2021 06:51:22 -0700 (PDT) Received: from localhost ([::1]:41532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9TN-0003WK-DH for importer2@patchew.org; Tue, 15 Jun 2021 09:51:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hj-0005yj-1y for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:19 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]:33790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hh-0002nM-Dg for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:18 -0400 Received: by mail-ed1-x531.google.com with SMTP id d7so3114140edx.0 for ; Tue, 15 Jun 2021 06:39:16 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hiu7ziiW42i1lxDyJDOcGawcWvmvcODGC75HldQeDRk=; b=lQxL379DhxgUWpAJfrA82dAZ0ysdESPV/NEVnr8aggPJxUFECQhTPHGtIrFzLVuvtu C8a9PhHzDPKUljMIsyTJdAR8SxEQzR6d7okmti/kpgpcC7TZUgvqm3kvbAaXwKmoOOMR egvlkBs1En077TNLayc4ItcDlB/rDpvchXr2jqYe2f6RUFkoHDiOl5d2owIH5ZkyRJ1d PxZh4xqAtJNLhi8PTjqk5R1cQ6OcjyGIr0WhsjhP/umvKfxAdq+3XbnDDWh99urWBhyy zP+A/JctyEmkCmW23qmDekHcgAbpAT0cV9OUIC8AFb2/9XVLqvh0SHWh2eYWar1f9c27 w3Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=hiu7ziiW42i1lxDyJDOcGawcWvmvcODGC75HldQeDRk=; b=NrJeGqAyMjSOZJIS8GTPoBbG4V6NweaCY5KANz/RAdicRdknAYr6KTrAcSMGlnjfDA 6J8Sejpvw+b9SyMR/nsGhT5eu6mHQbY47jd44QGndvozvfCMmvA13VKwJMiF+ruuDzCL GPcXLkhVnCJM/aoaI8UU02ZbfLR2LqRgIra65i3S0IoHPhpIjSAJom8BZ/C48jloHr+K kjuTLJ0iA9ta6u2f0g1WxlVA9KCuDU8ajpxUiMxqWyF0FxkiDjF5YO8KyyrD+/QjwGh8 1cCIaY5LY+JqtcuzeH7zUlAKgFjnDwdkJyX+fZyygj8YBqoVlZW99gmtX6co0umhx7OE UDCA== X-Gm-Message-State: AOAM533c0iwie2uOd8PmP/pDMBKAx+YaJ/p4Si8yrnn5ZXRFzIDN1m0Q gkfmI/V0ggdKyNGi4NunU6US8WFs5C4= X-Google-Smtp-Source: ABdhPJwr+cJ6MMta0BTczuubnzM2LVT/QuLplVvHjti4KW8/s0DpTjV2AcMfFznYkvsQF70Pk0xNPw== X-Received: by 2002:a05:6402:510e:: with SMTP id m14mr23346690edd.225.1623764356062; Tue, 15 Jun 2021 06:39:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 19/33] util/mmap-alloc: Factor out reserving of a memory region to mmap_reserve() Date: Tue, 15 Jun 2021 15:38:41 +0200 Message-Id: <20210615133855.775687-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x531.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , Igor Kotrasinski , Richard Henderson , Peter Xu , Murilo Opsfelder Araujo Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand We want to reserve a memory region without actually populating memory. Let's factor that out. Reviewed-by: Igor Kotrasinski Acked-by: Murilo Opsfelder Araujo Reviewed-by: Richard Henderson Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-3-david@redhat.com> Signed-off-by: Paolo Bonzini --- util/mmap-alloc.c | 58 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 24854064b4..223d66219c 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -82,6 +82,38 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return qemu_real_host_page_size; } =20 +/* + * Reserve a new memory region of the requested size to be used for mapping + * from the given fd (if any). + */ +static void *mmap_reserve(size_t size, int fd) +{ + int flags =3D MAP_PRIVATE; + +#if defined(__powerpc64__) && defined(__linux__) + /* + * On ppc64 mappings in the same segment (aka slice) must share the sa= me + * page size. Since we will be re-allocating part of this segment + * from the supplied fd, we should make sure to use the same page size= , to + * this end we mmap the supplied fd. In this case, set MAP_NORESERVE = to + * avoid allocating backing store memory. + * We do this unless we are using the system page size, in which case + * anonymous memory is OK. + */ + if (fd =3D=3D -1 || qemu_fd_getpagesize(fd) =3D=3D qemu_real_host_page= _size) { + fd =3D -1; + flags |=3D MAP_ANONYMOUS; + } else { + flags |=3D MAP_NORESERVE; + } +#else + fd =3D -1; + flags |=3D MAP_ANONYMOUS; +#endif + + return mmap(0, size, PROT_NONE, flags, fd, 0); +} + static inline size_t mmap_guard_pagesize(int fd) { #if defined(__powerpc64__) && defined(__linux__) @@ -104,7 +136,6 @@ void *qemu_ram_mmap(int fd, int prot; int flags; int map_sync_flags =3D 0; - int guardfd; size_t offset; size_t total; void *guardptr; @@ -116,30 +147,7 @@ void *qemu_ram_mmap(int fd, */ total =3D size + align; =20 -#if defined(__powerpc64__) && defined(__linux__) - /* On ppc64 mappings in the same segment (aka slice) must share the sa= me - * page size. Since we will be re-allocating part of this segment - * from the supplied fd, we should make sure to use the same page size= , to - * this end we mmap the supplied fd. In this case, set MAP_NORESERVE = to - * avoid allocating backing store memory. - * We do this unless we are using the system page size, in which case - * anonymous memory is OK. - */ - flags =3D MAP_PRIVATE; - if (fd =3D=3D -1 || guard_pagesize =3D=3D qemu_real_host_page_size) { - guardfd =3D -1; - flags |=3D MAP_ANONYMOUS; - } else { - guardfd =3D fd; - flags |=3D MAP_NORESERVE; - } -#else - guardfd =3D -1; - flags =3D MAP_PRIVATE | MAP_ANONYMOUS; -#endif - - guardptr =3D mmap(0, total, PROT_NONE, flags, guardfd, 0); - + guardptr =3D mmap_reserve(total, fd); if (guardptr =3D=3D MAP_FAILED) { return MAP_FAILED; } --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765573587434.46617579971746; Tue, 15 Jun 2021 06:59:33 -0700 (PDT) Received: from localhost ([::1]:43066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9bI-0006ce-1c for importer2@patchew.org; Tue, 15 Jun 2021 09:59:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hj-00061f-UQ for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:20 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:36545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hi-0002nX-3q for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:19 -0400 Received: by mail-ed1-x530.google.com with SMTP id w21so51111463edv.3 for ; Tue, 15 Jun 2021 06:39:17 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EUJcgMbiy+TJhdc0JIxQcF5/rLoJrViqR3WCrNaqHgA=; b=nv3Lk7Tti3H2EvstXvD8N5bmVk4YQk801eJQHHH4YLr74Remx+b0i8I8xcL5ixQWG6 gjOGn0nwwdHlyoYVQnJJq21Ni2UaRnzBy6ok4n2MQ7KxKQMFGFZcAgtlUhygB+Hi4thY 4UuJshzWNvqThZhqQf978RWy96ABsP8NCmlriwbxq/BcOMdrvcl/RQQOCW46OoMOv/79 5NetO6QFOBGrsl2ei3nGH1j3bWgxqfHvc9cZ5iWGPEwyZD36eP5+9bemRnIuBTngJbs1 xlOXbq59gNEFFxOYhfFL6GzC/95liVzV2E9WznY9OWmiosV40upB5iVaWnT+5KHjIAWG IQKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=EUJcgMbiy+TJhdc0JIxQcF5/rLoJrViqR3WCrNaqHgA=; b=UJkG2pLhieW9kjK4t9eNRiAgIU3zxoCCAtb+Cd7gVKe+Wa1WjjxPXpoE9TweerehBO N4aSj5Bz2iVytCERHepChy/3dR1jA0NrsG5jc2MINB5vIJS7ze8jsU/5rOF0+6OiHfJ+ me/s6+CRnCtqrMyl8nxwZ4xxdseGcFtG689ZN5Beg4W8K0a8Owj3xw0OzresR4JiYaGz XmjNJ0FD8mrVQ0yw97e04y4023iKGu9VEBJSPcxdx6XX85UsneRUoOwRzGpEFDpwyccv 5zK/vPO8imnh5evFJnou4iiJJLF9UwWgLroytivHs/8FIOR31Ab0/VQX2X4nZa5kWyFq IdxQ== X-Gm-Message-State: AOAM532H43ELco36LjmXxMab5TIormaJVtCf0xUf+V396UhiKOZqYz0V mKqVqE0ZAgG9aZ3R0IrGfX/K+eKp2KY= X-Google-Smtp-Source: ABdhPJyCoXxKzGXYb9CG8NlkpusC9dM1rv0DCesdVvkwzIJ93I5Yq/7h91GCfsM8qbVuFPyuIvGZJA== X-Received: by 2002:aa7:cd9a:: with SMTP id x26mr23261241edv.185.1623764356819; Tue, 15 Jun 2021 06:39:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 20/33] util/mmap-alloc: Factor out activating of memory to mmap_activate() Date: Tue, 15 Jun 2021 15:38:42 +0200 Message-Id: <20210615133855.775687-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Murilo Opsfelder Araujo , Richard Henderson , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand We want to activate memory within a reserved memory region, to make it accessible. Let's factor that out. Reviewed-by: Richard Henderson Acked-by: Murilo Opsfelder Araujo Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-4-david@redhat.com> Signed-off-by: Paolo Bonzini --- util/mmap-alloc.c | 94 +++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 223d66219c..0e2bd7bc0e 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -114,6 +114,52 @@ static void *mmap_reserve(size_t size, int fd) return mmap(0, size, PROT_NONE, flags, fd, 0); } =20 +/* + * Activate memory in a reserved region from the given fd (if any), to make + * it accessible. + */ +static void *mmap_activate(void *ptr, size_t size, int fd, bool readonly, + bool shared, bool is_pmem, off_t map_offset) +{ + const int prot =3D PROT_READ | (readonly ? 0 : PROT_WRITE); + int map_sync_flags =3D 0; + int flags =3D MAP_FIXED; + void *activated_ptr; + + flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; + flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; + if (shared && is_pmem) { + map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; + } + + activated_ptr =3D mmap(ptr, size, prot, flags | map_sync_flags, fd, + map_offset); + if (activated_ptr =3D=3D MAP_FAILED && map_sync_flags) { + if (errno =3D=3D ENOTSUP) { + char *proc_link =3D g_strdup_printf("/proc/self/fd/%d", fd); + char *file_name =3D g_malloc0(PATH_MAX); + int len =3D readlink(proc_link, file_name, PATH_MAX - 1); + + if (len < 0) { + len =3D 0; + } + file_name[len] =3D '\0'; + fprintf(stderr, "Warning: requesting persistence across crashe= s " + "for backend file %s failed. Proceeding without " + "persistence, data might become corrupted in case of h= ost " + "crash.\n", file_name); + g_free(proc_link); + g_free(file_name); + } + /* + * If mmap failed with MAP_SHARED_VALIDATE | MAP_SYNC, we will try + * again without these flags to handle backwards compatibility. + */ + activated_ptr =3D mmap(ptr, size, prot, flags, fd, map_offset); + } + return activated_ptr; +} + static inline size_t mmap_guard_pagesize(int fd) { #if defined(__powerpc64__) && defined(__linux__) @@ -133,13 +179,8 @@ void *qemu_ram_mmap(int fd, off_t map_offset) { const size_t guard_pagesize =3D mmap_guard_pagesize(fd); - int prot; - int flags; - int map_sync_flags =3D 0; - size_t offset; - size_t total; - void *guardptr; - void *ptr; + size_t offset, total; + void *ptr, *guardptr; =20 /* * Note: this always allocates at least one extra page of virtual addr= ess @@ -156,45 +197,10 @@ void *qemu_ram_mmap(int fd, /* Always align to host page size */ assert(align >=3D guard_pagesize); =20 - flags =3D MAP_FIXED; - flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; - flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; - if (shared && is_pmem) { - map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; - } - offset =3D QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guar= dptr; =20 - prot =3D PROT_READ | (readonly ? 0 : PROT_WRITE); - - ptr =3D mmap(guardptr + offset, size, prot, - flags | map_sync_flags, fd, map_offset); - - if (ptr =3D=3D MAP_FAILED && map_sync_flags) { - if (errno =3D=3D ENOTSUP) { - char *proc_link, *file_name; - int len; - proc_link =3D g_strdup_printf("/proc/self/fd/%d", fd); - file_name =3D g_malloc0(PATH_MAX); - len =3D readlink(proc_link, file_name, PATH_MAX - 1); - if (len < 0) { - len =3D 0; - } - file_name[len] =3D '\0'; - fprintf(stderr, "Warning: requesting persistence across crashe= s " - "for backend file %s failed. Proceeding without " - "persistence, data might become corrupted in case of h= ost " - "crash.\n", file_name); - g_free(proc_link); - g_free(file_name); - } - /* - * if map failed with MAP_SHARED_VALIDATE | MAP_SYNC, - * we will remove these flags to handle compatibility. - */ - ptr =3D mmap(guardptr + offset, size, prot, flags, fd, map_offset); - } - + ptr =3D mmap_activate(guardptr + offset, size, fd, readonly, shared, i= s_pmem, + map_offset); if (ptr =3D=3D MAP_FAILED) { munmap(guardptr, total); return MAP_FAILED; --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765335503967.11887449004; Tue, 15 Jun 2021 06:55:35 -0700 (PDT) Received: from localhost ([::1]:55042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9XS-0004Ay-BL for importer2@patchew.org; Tue, 15 Jun 2021 09:55:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Ho-00063t-No for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:25 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:42767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hi-0002oa-VN for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:20 -0400 Received: by mail-ej1-x633.google.com with SMTP id k25so22660852eja.9 for ; Tue, 15 Jun 2021 06:39:18 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PwhijkT5BerkG5mca/UyRrOW6T6V8fgDmI9azbvgpVw=; b=aHQ1pvkQlOcqhAScFruZngpmU9CkBX3aq0vcf3HFQNZjF6ZUoPF0O/d8+YtlErcjjh LrOCHLrcMgwL2gebD5h6JFD6GBiQxioR9Xi0uxrm2yZYjZ8HxKhKYXLCIUSpiZM+LKGe IL0l8oP0z1HvDdK3sEeQeYbNYeCFGs15AhfPZIILhKd6DMN2zkLZ4MCnGcHjqvBqLTOP kRHfKJ96IhcrX4FOE/aWjA1WjyjexJBhjbhjyOvUvM8oU4b4bIHRYCbRkb769srL+nxz xzrD0dCWeTMfnwi6nH+OjOaYhiQSb7HOeR9fMkObbeMw5X6y/zdWo/TKMCGmMErV0ZcJ UZwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=PwhijkT5BerkG5mca/UyRrOW6T6V8fgDmI9azbvgpVw=; b=PkempuWx/iAHDBTdpUTnFnm+LnKK0f3zKuLb19mvLz8DTa6CEbtjocdrYAEqt+nlLa 7SOgaAybaUwcOF1e0/5KM5ZJqwn+DBkifyohcH19SnfKyEYIgXUJTfDnfoLVX8UkEnWt BbZAnNq8Pkww592vMhref4Eh7jCs87OVVt6tCLoFRamVbyEHbNKv3kAR8N88pO5gTd8u A3mCmhHoAmNiGu8KMBm3RMbltIjpwXfv1nXVor4jhs0fhDtLSIPkhdukAwSXaCpzsZEZ N4iYcMZsDyky6mvuJiJsefFwsFcgJbyDoRKr/Ez4nktZa06PTYCShRTvXFn/I8ZmyXs8 Uxdw== X-Gm-Message-State: AOAM532FX0HvgLazQK+Spu5AMAm5evRg2CgjFmXveKts8aJ7rxoaIhXI zCfpJ2uP6Od137Sr7picd6M9EmxgBlM= X-Google-Smtp-Source: ABdhPJyy5+QjFFJVPhuCCtiUH2boMrQ1Lw3DARMFDS5Dt+4r/LrqQiHAuTVMSvvrxgbxGSeKli/g/w== X-Received: by 2002:a17:907:7b9d:: with SMTP id ne29mr21514392ejc.167.1623764357579; Tue, 15 Jun 2021 06:39:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 21/33] softmmu/memory: Pass ram_flags to qemu_ram_alloc_from_fd() Date: Tue, 15 Jun 2021 15:38:43 +0200 Message-Id: <20210615133855.775687-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x633.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's pass in ram flags just like we do with qemu_ram_alloc_from_file(), to clean up and prepare for more flags. Simplify the documentation of passed ram flags: Looking at our documentation of RAM_SHARED and RAM_PMEM is sufficient, no need to be repetitive. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-5-david@redhat.com> Signed-off-by: Paolo Bonzini --- backends/hostmem-memfd.c | 7 ++++--- hw/misc/ivshmem.c | 5 ++--- include/exec/memory.h | 9 +++------ include/exec/ram_addr.h | 6 +----- softmmu/memory.c | 7 +++---- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index da75e27057..3076da146d 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -35,6 +35,7 @@ static void memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { HostMemoryBackendMemfd *m =3D MEMORY_BACKEND_MEMFD(backend); + uint32_t ram_flags; char *name; int fd; =20 @@ -52,9 +53,9 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) } =20 name =3D host_memory_backend_get_name(backend); - memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), - name, backend->size, - backend->share, fd, 0, errp); + ram_flags =3D backend->share ? RAM_SHARED : 0; + memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, + backend->size, ram_flags, fd, 0, errp); g_free(name); } =20 diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index a1fa4878be..1ba4a98377 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -493,9 +493,8 @@ static void process_msg_shmem(IVShmemState *s, int fd, = Error **errp) size =3D buf.st_size; =20 /* mmap the region and map into the BAR2 */ - memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s), - "ivshmem.bar2", size, true, fd, 0, - &local_err); + memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s), "ivshmem.ba= r2", + size, RAM_SHARED, fd, 0, &local_err); if (local_err) { error_propagate(errp, local_err); return; diff --git a/include/exec/memory.h b/include/exec/memory.h index b114f5454b..8aa69a10d7 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1005,10 +1005,7 @@ void memory_region_init_resizeable_ram(MemoryRegion = *mr, * @size: size of the region. * @align: alignment of the region base address; if 0, the default alignme= nt * (getpagesize()) will be used. - * @ram_flags: Memory region features: - * - RAM_SHARED: memory must be mmaped with the MAP_SHARED flag - * - RAM_PMEM: the memory is persistent memory - * Other bits are ignored now. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. * @path: the path in which to allocate the RAM. * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens. @@ -1034,7 +1031,7 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, * @owner: the object that tracks the region's reference count * @name: the name of the region. * @size: size of the region. - * @share: %true if memory must be mmaped with the MAP_SHARED flag + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. * @fd: the fd to mmap. * @offset: offset within the file referenced by fd * @errp: pointer to Error*, to store an error if it happens. @@ -1046,7 +1043,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, - bool share, + uint32_t ram_flags, int fd, ram_addr_t offset, Error **errp); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 3cb9791df3..a7e3378340 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -104,11 +104,7 @@ long qemu_maxrampagesize(void); * Parameters: * @size: the size in bytes of the ram block * @mr: the memory region where the ram block is - * @ram_flags: specify the properties of the ram block, which can be one - * or bit-or of following values - * - RAM_SHARED: mmap the backing file or device with MAP_SHA= RED - * - RAM_PMEM: the backend @mem_path or @fd is persistent mem= ory - * Other bits are ignored. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. * @mem_path or @fd: specify the backing file or device * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens diff --git a/softmmu/memory.c b/softmmu/memory.c index c19b0be6b1..f777504ac5 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1609,7 +1609,7 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, Object *owner, const char *name, uint64_t size, - bool share, + uint32_t ram_flags, int fd, ram_addr_t offset, Error **errp) @@ -1619,9 +1619,8 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc_from_fd(size, mr, - share ? RAM_SHARED : 0, - fd, offset, false, &err); + mr->ram_block =3D qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, offs= et, + false, &err); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623766009839171.37448831375445; Tue, 15 Jun 2021 07:06:49 -0700 (PDT) Received: from localhost ([::1]:60146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9iL-0001Kh-47 for importer2@patchew.org; Tue, 15 Jun 2021 10:06:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Ho-00063u-OC for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:25 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]:39927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hj-0002p9-IU for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:21 -0400 Received: by mail-ej1-x632.google.com with SMTP id l1so22570472ejb.6 for ; Tue, 15 Jun 2021 06:39:19 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YMm+chGMuEmvwUOD656u7hYjmYt4rPQiwOfC+Eir/mc=; b=Lwsw/joBVnxLiiFJBFNWkNyQ9MsChSy56c9MiUXwx363P7m5fgMnVptkG2NKuHzYfn da+oIXicnS98Phi3e0G9Q/T+Uv8f44XKWQ9wSwZJFKj02RrxOgTjYmNgK22a+NLjz5ON xx6/3B7jmCyBr5VoWYtj40l3GYkjnVCTKZDvupWL5Mkv1vRbiKYuvkIp8eFLlAUsqcm5 PbkiGMhDI0VFus7vkZe3cnBUxQupDx9w6YXKTKH7pyRnsso+aD3fVsnd9tgl47KJhdIh voktz4DZ7nay6nN2THowUlf5ZbvhBCv87bdh2SiV4T6xvvJddMVMI/BTmBOP/dIOLXIg Ea6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=YMm+chGMuEmvwUOD656u7hYjmYt4rPQiwOfC+Eir/mc=; b=kNNYLIVBmY4vj9Bce/w70PkAyVNpfmkgbdWKC0RxSlvJRHUAMb7Ib7kjjNa4VVVbO/ pZufH8EjxRHu14h4Ub4ZAv3eHmRoQr+5fcrZhnaX0RrqTZRn9ej8jHwJk5NqopavIeHq eypHXESR4F3ulY4ZOFfVa/GVwfq4eyQKEPTedkmFXelgU+C3m7AFhbyZSIrZoYA2nFoG 2dsdMEuvtHyjL21t0qpvqGrqJImLqG9DUbKzO8vDgK1Q1eLq4eq73fmiF6NHd3KJZVj5 DYRbiHYfWliz3f2Q7wx7IGcUQiRv3AU6Ul5Hw0tPUwCVai6Q5HvD6FrzHoQGeVOpQ1cp IpSA== X-Gm-Message-State: AOAM530xoJfYzP3GUXUIjmL5M+CUpuwtJ/dEQO1U0ijkuXJzOJ4z8pcH SLN30P6fw+PoJHVQL7KY+5qBSciDTkU= X-Google-Smtp-Source: ABdhPJyGGUStEyGqCPVJ9thMfykfcq+nGmgvGkVz2cJixbsuHE3TA+sv6cv91YEyWzX3isRoAbAVCQ== X-Received: by 2002:a17:906:b855:: with SMTP id ga21mr20943000ejb.550.1623764358308; Tue, 15 Jun 2021 06:39:18 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 22/33] softmmu/memory: Pass ram_flags to memory_region_init_ram_shared_nomigrate() Date: Tue, 15 Jun 2021 15:38:44 +0200 Message-Id: <20210615133855.775687-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::632; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x632.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's forward ram_flags instead, renaming memory_region_init_ram_shared_nomigrate() into memory_region_init_ram_flags_nomigrate(). Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-6-david@redhat.com> Signed-off-by: Paolo Bonzini --- backends/hostmem-ram.c | 6 +++-- hw/m68k/next-cube.c | 4 ++-- include/exec/memory.h | 24 +++++++++---------- .../memory-region-housekeeping.cocci | 8 +++---- softmmu/memory.c | 18 +++++++------- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index 5cc53e76c9..741e701062 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -19,6 +19,7 @@ static void ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { + uint32_t ram_flags; char *name; =20 if (!backend->size) { @@ -27,8 +28,9 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Erro= r **errp) } =20 name =3D host_memory_backend_get_name(backend); - memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend),= name, - backend->size, backend->share, errp); + ram_flags =3D backend->share ? RAM_SHARED : 0; + memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), = name, + backend->size, ram_flags, errp); g_free(name); } =20 diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c index de951ffe5d..e0d4a94f9d 100644 --- a/hw/m68k/next-cube.c +++ b/hw/m68k/next-cube.c @@ -984,8 +984,8 @@ static void next_cube_init(MachineState *machine) sysbus_mmio_map(SYS_BUS_DEVICE(pcdev), 1, 0x02100000); =20 /* BMAP memory */ - memory_region_init_ram_shared_nomigrate(bmapm1, NULL, "next.bmapmem", = 64, - true, &error_fatal); + memory_region_init_ram_flags_nomigrate(bmapm1, NULL, "next.bmapmem", 6= 4, + RAM_SHARED, &error_fatal); memory_region_add_subregion(sysmem, 0x020c0000, bmapm1); /* The Rev_2.5_v66.bin firmware accesses it at 0x820c0020, too */ memory_region_init_alias(bmapm2, NULL, "next.bmapmem2", bmapm1, 0x0, 6= 4); diff --git a/include/exec/memory.h b/include/exec/memory.h index 8aa69a10d7..b1f8fa1df0 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -940,27 +940,27 @@ void memory_region_init_ram_nomigrate(MemoryRegion *m= r, Error **errp); =20 /** - * memory_region_init_ram_shared_nomigrate: Initialize RAM memory region. - * Accesses into the region will - * modify memory directly. + * memory_region_init_ram_flags_nomigrate: Initialize RAM memory region. + * Accesses into the region will + * modify memory directly. * * @mr: the #MemoryRegion to be initialized. * @owner: the object that tracks the region's reference count * @name: Region name, becomes part of RAMBlock name used in migration str= eam * must be unique within any device * @size: size of the region. - * @share: allow remapping RAM to different addresses + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED. * @errp: pointer to Error*, to store an error if it happens. * - * Note that this function is similar to memory_region_init_ram_nomigrate. - * The only difference is part of the RAM region can be remapped. + * Note that this function does not do anything to cause the data in the + * RAM memory region to be migrated; that is the responsibility of the cal= ler. */ -void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - bool share, - Error **errp); +void memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, + Object *owner, + const char *name, + uint64_t size, + uint32_t ram_flags, + Error **errp); =20 /** * memory_region_init_resizeable_ram: Initialize memory region with resiz= eable diff --git a/scripts/coccinelle/memory-region-housekeeping.cocci b/scripts/= coccinelle/memory-region-housekeeping.cocci index c768d8140a..29651ebde9 100644 --- a/scripts/coccinelle/memory-region-housekeeping.cocci +++ b/scripts/coccinelle/memory-region-housekeeping.cocci @@ -127,8 +127,8 @@ static void device_fn(DeviceState *dev, ...) - memory_region_init_rom(E1, NULL, E2, E3, E4); + memory_region_init_rom(E1, obj, E2, E3, E4); | -- memory_region_init_ram_shared_nomigrate(E1, NULL, E2, E3, E4, E5); -+ memory_region_init_ram_shared_nomigrate(E1, obj, E2, E3, E4, E5); +- memory_region_init_ram_flags_nomigrate(E1, NULL, E2, E3, E4, E5); ++ memory_region_init_ram_flags_nomigrate(E1, obj, E2, E3, E4, E5); ) ...+> } @@ -152,8 +152,8 @@ static void device_fn(DeviceState *dev, ...) - memory_region_init_rom(E1, NULL, E2, E3, E4); + memory_region_init_rom(E1, OBJECT(dev), E2, E3, E4); | -- memory_region_init_ram_shared_nomigrate(E1, NULL, E2, E3, E4, E5); -+ memory_region_init_ram_shared_nomigrate(E1, OBJECT(dev), E2, E3, E4, E5); +- memory_region_init_ram_flags_nomigrate(E1, NULL, E2, E3, E4, E5); ++ memory_region_init_ram_flags_nomigrate(E1, OBJECT(dev), E2, E3, E4, E5); ) ...+> } diff --git a/softmmu/memory.c b/softmmu/memory.c index f777504ac5..5c0ff76c06 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1531,22 +1531,22 @@ void memory_region_init_ram_nomigrate(MemoryRegion = *mr, uint64_t size, Error **errp) { - memory_region_init_ram_shared_nomigrate(mr, owner, name, size, false, = errp); + memory_region_init_ram_flags_nomigrate(mr, owner, name, size, 0, errp); } =20 -void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, - Object *owner, - const char *name, - uint64_t size, - bool share, - Error **errp) +void memory_region_init_ram_flags_nomigrate(MemoryRegion *mr, + Object *owner, + const char *name, + uint64_t size, + uint32_t ram_flags, + Error **errp) { Error *err =3D NULL; memory_region_init(mr, owner, name, size); mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc(size, share, mr, &err); + mr->ram_block =3D qemu_ram_alloc(size, ram_flags & RAM_SHARED, mr, &er= r); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); @@ -1682,7 +1682,7 @@ void memory_region_init_rom_nomigrate(MemoryRegion *m= r, uint64_t size, Error **errp) { - memory_region_init_ram_shared_nomigrate(mr, owner, name, size, false, = errp); + memory_region_init_ram_flags_nomigrate(mr, owner, name, size, 0, errp); mr->readonly =3D true; } =20 --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765774008748.8147777413022; Tue, 15 Jun 2021 07:02:54 -0700 (PDT) Received: from localhost ([::1]:51566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9eW-0003ws-NO for importer2@patchew.org; Tue, 15 Jun 2021 10:02:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Ho-00064L-SG for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:25 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:45873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hk-0002pb-87 for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:21 -0400 Received: by mail-ej1-x633.google.com with SMTP id k7so22629752ejv.12 for ; Tue, 15 Jun 2021 06:39:19 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bp5DsEozRLdC1rdlEukZgjqBm7Ifa5wIv6NCq/QVsYM=; b=FmiebxdmEXJZfLOFYc6XA/dKy/Ov+HcI3u0U7OUCLMgrmJppOhcfx249GWJZ4WTFVk KriEJ/v18PJgM6S71xLwEQ/3mTjp72CKdxRod82bYkJeY/1qrNvWO6sSBQy4JY+Gomuf DJ2uRZmTdklICbFjKOeXYhDKTfy1AZNNiHmHM6VIn6NbkcBLvoUHDVlcTJvEhwntTZSi UvgB/wJTJnuPr3lE/n04h2f6AfzXQDbqibCxwGTSgqDaU9twYjVwSeEws8slTf9p5NDk 3NwChbfbZ849cWrGy2gVAP2zJKEEBTYLR+0D55QEviOwoATqj61pRDicYVaeUOcqF6ve y71w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Bp5DsEozRLdC1rdlEukZgjqBm7Ifa5wIv6NCq/QVsYM=; b=MPGIqJNsM3VZ21uC/YjknfSycFdUg1LDeTlnP1k4waLVgAIUdrdnaMKHWuCW8OntcS 9QLgJhyGPdRo8ugyQlTYJ6xypOY1/VAd5JRGP/Fzc5lsZ/n3FHgTvbdZVF0vAihYBH7D ZYcuni2iIhdXtbdt2nKWCVfk4Q3iUa6VmNKKweeYingVih1ScajuByYt5olHdyYQ3YGq V49OzMgSY3AqtjX33+c/KDp065olPlQRcAHliuNqnngoj+0cFBwdjdx/8D/+ElMT+ex8 9AL7JMlnU1EUALCbKsgWtKjpbIvCBflOTkJ3M5l8tSwsvCtAAHqYdyTWvnlC5yVlDEkf FgIQ== X-Gm-Message-State: AOAM53298LKiUyd9ndGoOshqPEq+4QjU0UALAEGOvqVsPSpkbfBN2DWP SKdzqJ8TgaW1+cbCCwY2LaXOFefzLjU= X-Google-Smtp-Source: ABdhPJwjK5/ojiIXLOnUA8Hyswvb5cz469w9Mnbuo6Na+NQXmwXcIO9thkcGtBuJ2H3eqGQ3ux3B0g== X-Received: by 2002:a17:906:d15a:: with SMTP id br26mr21369843ejb.232.1623764359003; Tue, 15 Jun 2021 06:39:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 23/33] softmmu/memory: Pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal() Date: Tue, 15 Jun 2021 15:38:45 +0200 Message-Id: <20210615133855.775687-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x633.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal(), preparing for passing additional flags. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-7-david@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/ram_addr.h | 2 +- softmmu/memory.c | 4 ++-- softmmu/physmem.c | 29 ++++++++++++----------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index a7e3378340..6d4513f8e2 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -122,7 +122,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Memor= yRegion *mr, =20 RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); -RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr, +RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion= *mr, Error **errp); RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size, void (*resized)(const char*, diff --git a/softmmu/memory.c b/softmmu/memory.c index 5c0ff76c06..f0161515e9 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1546,7 +1546,7 @@ void memory_region_init_ram_flags_nomigrate(MemoryReg= ion *mr, mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc(size, ram_flags & RAM_SHARED, mr, &er= r); + mr->ram_block =3D qemu_ram_alloc(size, ram_flags, mr, &err); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); @@ -1702,7 +1702,7 @@ void memory_region_init_rom_device_nomigrate(MemoryRe= gion *mr, mr->terminates =3D true; mr->rom_device =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc(size, false, mr, &err); + mr->ram_block =3D qemu_ram_alloc(size, 0, mr, &err); if (err) { mr->size =3D int128_zero(); object_unparent(OBJECT(mr)); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 2f106d0680..f7adf544df 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2128,12 +2128,15 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, = ram_addr_t max_size, void (*resized)(const char*, uint64_t length, void *host), - void *host, bool resizeable, bool share, + void *host, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { RAMBlock *new_block; Error *local_err =3D NULL; =20 + assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) =3D= =3D 0); + assert(!host ^ (ram_flags & RAM_PREALLOC)); + size =3D HOST_PAGE_ALIGN(size); max_size =3D HOST_PAGE_ALIGN(max_size); new_block =3D g_malloc0(sizeof(*new_block)); @@ -2145,15 +2148,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, r= am_addr_t max_size, new_block->fd =3D -1; new_block->page_size =3D qemu_real_host_page_size; new_block->host =3D host; - if (host) { - new_block->flags |=3D RAM_PREALLOC; - } - if (share) { - new_block->flags |=3D RAM_SHARED; - } - if (resizeable) { - new_block->flags |=3D RAM_RESIZEABLE; - } + new_block->flags =3D ram_flags; ram_block_add(new_block, &local_err); if (local_err) { g_free(new_block); @@ -2166,15 +2161,15 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, = ram_addr_t max_size, RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp) { - return qemu_ram_alloc_internal(size, size, NULL, host, false, - false, mr, errp); + return qemu_ram_alloc_internal(size, size, NULL, host, RAM_PREALLOC, m= r, + errp); } =20 -RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, +RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { - return qemu_ram_alloc_internal(size, size, NULL, NULL, false, - share, mr, errp); + assert((ram_flags & ~RAM_SHARED) =3D=3D 0); + return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, = errp); } =20 RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t maxsz, @@ -2183,8 +2178,8 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, = ram_addr_t maxsz, void *host), MemoryRegion *mr, Error **errp) { - return qemu_ram_alloc_internal(size, maxsz, resized, NULL, true, - false, mr, errp); + return qemu_ram_alloc_internal(size, maxsz, resized, NULL, + RAM_RESIZEABLE, mr, errp); } =20 static void reclaim_ramblock(RAMBlock *block) --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765264440428.24508082416025; Tue, 15 Jun 2021 06:54:24 -0700 (PDT) Received: from localhost ([::1]:51036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9WJ-0001Px-2x for importer2@patchew.org; Tue, 15 Jun 2021 09:54:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hs-000696-CY for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:28 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:33338) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Ho-0002q6-HD for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:27 -0400 Received: by mail-ej1-x62f.google.com with SMTP id g20so22743447ejt.0 for ; Tue, 15 Jun 2021 06:39:20 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4DaNgxtbFj1o9ArXDPgAOWKe6je7pzt3SqodLCekQfY=; b=mf0cAO3PKXIpBn/qI8X8Un7+K5dz7bs7nmvUr1rYmN4ajYF6uu5mpt2NRAdglbrp/5 hcDUNK6ywg7bvXvuzA6HH1I9icWjPsnExHXC8iqGlktkokqcnrbwKmz84zX9RlLfRHve An2tW5XoXkqYkpaVOwR4GwNykTPlztz+ObZkQyZHzgXhsHE+h4w+HzLIKzlLEwdunN5f 3b4NpOtXeGKmR7d8+npOrmE5ompl3giRI8PYBsdRASZZICJpW8EGmaMY3N3qD9mu6fx8 xdJfjVg7swn8z356vkC1OOcXlfbKuU6RTMqtGOXcBqAk48AHv9LUUYfk4laMopZMtaBo H/lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=4DaNgxtbFj1o9ArXDPgAOWKe6je7pzt3SqodLCekQfY=; b=lQWbyyRdqG60vN9FVZVHhuXEnAY0sQNmPiabf7JVegi9tJI6SUV6zp0owV6/RDyU7I HCFQODCiz2BdgReEoxOxknYsHFJlBFh+LoNZG9ERNfRoZqxC9xCCJ99gpXbYJMK82BYn Om9Z46jEi8r2lHcp0WRbLMtCxf5jotvOe7o4NEwTlB2NET+VjmYxjYoW0KGZzoYt/01V +IjKpOfsxW6M3CtTbJVQFPxfb7Cht6E/+LlVZfZu3Ft3w/a5fDQ1wGqNKinrVMqSVdZQ M7lRWJb0wokmPhiqsJroBTXYw6PdO6n5u035s6FGKMwSptkgipZNsE0R48q3u+msqZug hQsA== X-Gm-Message-State: AOAM532hQTCP6LFwnRsnPq4bdYrdC6mH5vOtV3AXQ8XvFY3yrWHkV/Oa 5M4kZIjrFU4PXkYPevC2FJkiRZbT00w= X-Google-Smtp-Source: ABdhPJyLSa5R5xcOixBdLjO25MeyB911Utqi+OotoZxkqqHB7KkD/X3KckoGE+4zkhi62Q4w6jWHAQ== X-Received: by 2002:a17:906:f289:: with SMTP id gu9mr3896856ejb.157.1623764359798; Tue, 15 Jun 2021 06:39:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 24/33] util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap() Date: Tue, 15 Jun 2021 15:38:46 +0200 Message-Id: <20210615133855.775687-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62f.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's pass flags instead of bools to prepare for passing other flags and update the documentation of qemu_ram_mmap(). Introduce new QEMU_MAP_ flags that abstract the mmap() PROT_ and MAP_ flag handling and simplify it. We expose only flags that are currently supported by qemu_ram_mmap(). Maybe, we'll see qemu_mmap() in the future as well that can implement these flags. Note: We don't use MAP_ flags as some flags (e.g., MAP_SYNC) are only defined for some systems and we want to always be able to identify these flags reliably inside qemu_ram_mmap() -- for example, to properly warn when some future flags are not available or effective on a system. Also, this way we can simplify PROT_ handling as well. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-8-david@redhat.com> Signed-off-by: Paolo Bonzini --- include/qemu/mmap-alloc.h | 16 +++++++++------- include/qemu/osdep.h | 18 ++++++++++++++++++ softmmu/physmem.c | 8 +++++--- util/mmap-alloc.c | 15 ++++++++------- util/oslib-posix.c | 3 ++- 5 files changed, 42 insertions(+), 18 deletions(-) diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index 456ff87df1..90d0eee705 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -7,18 +7,22 @@ size_t qemu_fd_getpagesize(int fd); size_t qemu_mempath_getpagesize(const char *mem_path); =20 /** - * qemu_ram_mmap: mmap the specified file or device. + * qemu_ram_mmap: mmap anonymous memory, the specified file or device. + * + * mmap() abstraction to map guest RAM, simplifying flag handling, taking + * care of alignment requirements and installing guard pages. * * Parameters: * @fd: the file or the device to mmap * @size: the number of bytes to be mmaped * @align: if not zero, specify the alignment of the starting mapping add= ress; * otherwise, the alignment in use will be determined by QEMU. - * @readonly: true for a read-only mapping, false for read/write. - * @shared: map has RAM_SHARED flag. - * @is_pmem: map has RAM_PMEM flag. + * @qemu_map_flags: QEMU_MAP_* flags * @map_offset: map starts at offset of map_offset from the start of fd * + * Internally, MAP_PRIVATE, MAP_ANONYMOUS and MAP_SHARED_VALIDATE are set + * implicitly based on other parameters. + * * Return: * On success, return a pointer to the mapped area. * On failure, return MAP_FAILED. @@ -26,9 +30,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path); void *qemu_ram_mmap(int fd, size_t size, size_t align, - bool readonly, - bool shared, - bool is_pmem, + uint32_t qemu_map_flags, off_t map_offset); =20 void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 4c6f2390be..88106e88fc 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -366,6 +366,24 @@ void *qemu_anon_ram_alloc(size_t size, uint64_t *align= , bool shared); void qemu_vfree(void *ptr); void qemu_anon_ram_free(void *ptr, size_t size); =20 +/* + * Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example, + * consumed by qemu_ram_mmap(). + */ + +/* Map PROT_READ instead of PROT_READ | PROT_WRITE. */ +#define QEMU_MAP_READONLY (1 << 0) + +/* Use MAP_SHARED instead of MAP_PRIVATE. */ +#define QEMU_MAP_SHARED (1 << 1) + +/* + * Use MAP_SYNC | MAP_SHARED_VALIDATE if supported. Ignored without + * QEMU_MAP_SHARED. If mapping fails, warn and fallback to !QEMU_MAP_SYNC. + */ +#define QEMU_MAP_SYNC (1 << 2) + + #define QEMU_MADV_INVALID -1 =20 #if defined(CONFIG_MADVISE) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index f7adf544df..24228c838c 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1540,6 +1540,7 @@ static void *file_ram_alloc(RAMBlock *block, off_t offset, Error **errp) { + uint32_t qemu_map_flags; void *area; =20 block->page_size =3D qemu_fd_getpagesize(fd); @@ -1587,9 +1588,10 @@ static void *file_ram_alloc(RAMBlock *block, perror("ftruncate"); } =20 - area =3D qemu_ram_mmap(fd, memory, block->mr->align, readonly, - block->flags & RAM_SHARED, block->flags & RAM_PME= M, - offset); + qemu_map_flags =3D readonly ? QEMU_MAP_READONLY : 0; + qemu_map_flags |=3D (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0; + qemu_map_flags |=3D (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0; + area =3D qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, o= ffset); if (area =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 0e2bd7bc0e..1ddc0e2a1e 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -118,9 +118,12 @@ static void *mmap_reserve(size_t size, int fd) * Activate memory in a reserved region from the given fd (if any), to make * it accessible. */ -static void *mmap_activate(void *ptr, size_t size, int fd, bool readonly, - bool shared, bool is_pmem, off_t map_offset) +static void *mmap_activate(void *ptr, size_t size, int fd, + uint32_t qemu_map_flags, off_t map_offset) { + const bool readonly =3D qemu_map_flags & QEMU_MAP_READONLY; + const bool shared =3D qemu_map_flags & QEMU_MAP_SHARED; + const bool sync =3D qemu_map_flags & QEMU_MAP_SYNC; const int prot =3D PROT_READ | (readonly ? 0 : PROT_WRITE); int map_sync_flags =3D 0; int flags =3D MAP_FIXED; @@ -128,7 +131,7 @@ static void *mmap_activate(void *ptr, size_t size, int = fd, bool readonly, =20 flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; - if (shared && is_pmem) { + if (shared && sync) { map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; } =20 @@ -173,9 +176,7 @@ static inline size_t mmap_guard_pagesize(int fd) void *qemu_ram_mmap(int fd, size_t size, size_t align, - bool readonly, - bool shared, - bool is_pmem, + uint32_t qemu_map_flags, off_t map_offset) { const size_t guard_pagesize =3D mmap_guard_pagesize(fd); @@ -199,7 +200,7 @@ void *qemu_ram_mmap(int fd, =20 offset =3D QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guar= dptr; =20 - ptr =3D mmap_activate(guardptr + offset, size, fd, readonly, shared, i= s_pmem, + ptr =3D mmap_activate(guardptr + offset, size, fd, qemu_map_flags, map_offset); if (ptr =3D=3D MAP_FAILED) { munmap(guardptr, total); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 7b4bec1402..0dd7784a88 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -229,8 +229,9 @@ void *qemu_memalign(size_t alignment, size_t size) /* alloc shared memory pages */ void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) { + const uint32_t qemu_map_flags =3D shared ? QEMU_MAP_SHARED : 0; size_t align =3D QEMU_VMALLOC_ALIGN; - void *ptr =3D qemu_ram_mmap(-1, size, align, false, shared, false, 0); + void *ptr =3D qemu_ram_mmap(-1, size, align, qemu_map_flags, 0); =20 if (ptr =3D=3D MAP_FAILED) { return NULL; --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623766508418524.793394167849; Tue, 15 Jun 2021 07:15:08 -0700 (PDT) Received: from localhost ([::1]:56990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9qN-0001so-6E for importer2@patchew.org; Tue, 15 Jun 2021 10:15:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hu-0006D8-Bd for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:44911) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hq-0002qs-6o for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:29 -0400 Received: by mail-ej1-x630.google.com with SMTP id gt18so4153980ejc.11 for ; Tue, 15 Jun 2021 06:39:21 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=buGOH7XUq92PFXNAgM40ZqSCuPs0ldahTRIbvBcpUuw=; b=QjXMGpeisGSO1V7un+piWXZtVPKroXzEZkbsOuowTY5L89uqEx4W+p5Sp2vEffKmQP 3CY8beU74oSwxPDdu00X16j5HbGl3s0i18sQ6lvOhZaZMN1PERyPKQpDobN7X+RkMBao yzMPDdU26Apkae1I2mZ4AuIJSZAdaWae9zAXCcqePCzXTqb8YzfK3sNJRydOFt3xT2xJ jqTGWrgUcRx/i74puw/UOEShzy9w4UumakfSP/ODva6/yloN3SqsL+1EA2c1SNUVH6OH mf7HFb76qNnsyhRJqqtqdaIj59/2wGx2HreYcYO7Ir42AcU6XeBl2QyIvNf1JUAYBjka nsnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=buGOH7XUq92PFXNAgM40ZqSCuPs0ldahTRIbvBcpUuw=; b=Cma5bjpwWQ+ZinqL3qSTlmnQ8LTYETkyIcn/winA/VbwRGTn/HQH2LtAGQveokGizT ybmUzMcJ4X4BWs6Kyks1W07kxA6pJ6isECxHPlANaPE93huQ5nzbb46RBtP+zXLEKEw8 sqIKuLqwX0e0kluTzChX8dAmG0rE71goBVJ3+R9J1afIOzJbSY9gZJ/3M/Lrq+xOYu4S YeapP6BKWKM3y7a/pyTQGTSrFxaZTJqQctvrnOZy1XkqvG7kjWM16W/Dw2wmhpdPcBGC Ny9AylLSbZhUQ94uETUThqi8VBZm3s86xIQWfaTxTbJIVXS9nECmGeGc6n4d1IiBdKUz BQUQ== X-Gm-Message-State: AOAM530rvApG0dqdInwrTOEt58zUhjIpv8wwBT0Qczu7E0yFMhboFg90 hoHKjOd0nUuNJJUaLHqegds3kXxGdXM= X-Google-Smtp-Source: ABdhPJyqpb9LFs+PIuvOpMkb0cLQrP2qpkP3tKHhvfC7lBCG8YZcmi+193paboxX+ccvi8MYE8VNUA== X-Received: by 2002:a17:907:7b9e:: with SMTP id ne30mr21174283ejc.389.1623764360896; Tue, 15 Jun 2021 06:39:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 25/33] memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap() Date: Tue, 15 Jun 2021 15:38:47 +0200 Message-Id: <20210615133855.775687-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x630.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's introduce RAM_NORESERVE, allowing mmap'ing with MAP_NORESERVE. The new flag has the following semantics: " RAM is mmap-ed with MAP_NORESERVE. When set, reserving swap space (or huge pages if applicable) is skipped: will bail out if not supported. When not set, the OS will do the reservation, if supported for the memory type. " Allow passing it into: - memory_region_init_ram_nomigrate() - memory_region_init_resizeable_ram() - memory_region_init_ram_from_file() ... and teach qemu_ram_mmap() and qemu_anon_ram_alloc() about the flag. Bail out if the flag is not supported, which is the case right now for both, POSIX and win32. We will add Linux support next and allow specifying RAM_NORESERVE via memory backends. The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-9-david@redhat.com> Signed-off-by: Paolo Bonzini --- include/exec/cpu-common.h | 1 + include/exec/memory.h | 15 ++++++++++++--- include/exec/ram_addr.h | 3 ++- include/qemu/osdep.h | 9 ++++++++- migration/ram.c | 3 +-- softmmu/physmem.c | 15 ++++++++++++--- util/mmap-alloc.c | 7 +++++++ util/oslib-posix.c | 6 ++++-- util/oslib-win32.c | 13 ++++++++++++- 9 files changed, 59 insertions(+), 13 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index ccabed4003..039d422bf4 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -59,6 +59,7 @@ ram_addr_t qemu_ram_get_offset(RAMBlock *rb); ram_addr_t qemu_ram_get_used_length(RAMBlock *rb); ram_addr_t qemu_ram_get_max_length(RAMBlock *rb); bool qemu_ram_is_shared(RAMBlock *rb); +bool qemu_ram_is_noreserve(RAMBlock *rb); bool qemu_ram_is_uf_zeroable(RAMBlock *rb); void qemu_ram_set_uf_zeroable(RAMBlock *rb); bool qemu_ram_is_migratable(RAMBlock *rb); diff --git a/include/exec/memory.h b/include/exec/memory.h index b1f8fa1df0..b116f7c64e 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -155,6 +155,13 @@ typedef struct IOMMUTLBEvent { */ #define RAM_UF_WRITEPROTECT (1 << 6) =20 +/* + * RAM is mmap-ed with MAP_NORESERVE. When set, reserving swap space (or h= uge + * pages if applicable) is skipped: will bail out if not supported. When n= ot + * set, the OS will do the reservation, if supported for the memory type. + */ +#define RAM_NORESERVE (1 << 7) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, @@ -949,7 +956,7 @@ void memory_region_init_ram_nomigrate(MemoryRegion *mr, * @name: Region name, becomes part of RAMBlock name used in migration str= eam * must be unique within any device * @size: size of the region. - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_NORESERVE. * @errp: pointer to Error*, to store an error if it happens. * * Note that this function does not do anything to cause the data in the @@ -1005,7 +1012,8 @@ void memory_region_init_resizeable_ram(MemoryRegion *= mr, * @size: size of the region. * @align: alignment of the region base address; if 0, the default alignme= nt * (getpagesize()) will be used. - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE, * @path: the path in which to allocate the RAM. * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens. @@ -1031,7 +1039,8 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, * @owner: the object that tracks the region's reference count * @name: the name of the region. * @size: size of the region. - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE. * @fd: the fd to mmap. * @offset: offset within the file referenced by fd * @errp: pointer to Error*, to store an error if it happens. diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 6d4513f8e2..551876bed0 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -104,7 +104,8 @@ long qemu_maxrampagesize(void); * Parameters: * @size: the size in bytes of the ram block * @mr: the memory region where the ram block is - * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM. + * @ram_flags: RamBlock flags. Supported flags: RAM_SHARED, RAM_PMEM, + * RAM_NORESERVE. * @mem_path or @fd: specify the backing file or device * @readonly: true to open @path for reading, false for read/write. * @errp: pointer to Error*, to store an error if it happens diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 88106e88fc..38a3327db9 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -362,7 +362,8 @@ extern "C" { int qemu_daemon(int nochdir, int noclose); void *qemu_try_memalign(size_t alignment, size_t size); void *qemu_memalign(size_t alignment, size_t size); -void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared); +void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, + bool noreserve); void qemu_vfree(void *ptr); void qemu_anon_ram_free(void *ptr, size_t size); =20 @@ -383,6 +384,12 @@ void qemu_anon_ram_free(void *ptr, size_t size); */ #define QEMU_MAP_SYNC (1 << 2) =20 +/* + * Use MAP_NORESERVE to skip reservation of swap space (or huge pages if + * applicable). Bail out if not supported/effective. + */ +#define QEMU_MAP_NORESERVE (1 << 3) + =20 #define QEMU_MADV_INVALID -1 =20 diff --git a/migration/ram.c b/migration/ram.c index 60ea913c54..723af67c2e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3343,8 +3343,7 @@ int colo_init_ram_cache(void) WITH_RCU_READ_LOCK_GUARD() { RAMBLOCK_FOREACH_NOT_IGNORED(block) { block->colo_cache =3D qemu_anon_ram_alloc(block->used_length, - NULL, - false); + NULL, false, false); if (!block->colo_cache) { error_report("%s: Can't alloc memory for COLO cache of blo= ck %s," "size 0x" RAM_ADDR_FMT, __func__, block->idst= r, diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 24228c838c..a7725d8474 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1591,6 +1591,7 @@ static void *file_ram_alloc(RAMBlock *block, qemu_map_flags =3D readonly ? QEMU_MAP_READONLY : 0; qemu_map_flags |=3D (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0; qemu_map_flags |=3D (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0; + qemu_map_flags |=3D (block->flags & RAM_NORESERVE) ? QEMU_MAP_NORESERV= E : 0; area =3D qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, o= ffset); if (area =3D=3D MAP_FAILED) { error_setg_errno(errp, errno, @@ -1716,6 +1717,11 @@ bool qemu_ram_is_shared(RAMBlock *rb) return rb->flags & RAM_SHARED; } =20 +bool qemu_ram_is_noreserve(RAMBlock *rb) +{ + return rb->flags & RAM_NORESERVE; +} + /* Note: Only set at the start of postcopy */ bool qemu_ram_is_uf_zeroable(RAMBlock *rb) { @@ -1950,6 +1956,7 @@ static void dirty_memory_extend(ram_addr_t old_ram_si= ze, =20 static void ram_block_add(RAMBlock *new_block, Error **errp) { + const bool noreserve =3D qemu_ram_is_noreserve(new_block); const bool shared =3D qemu_ram_is_shared(new_block); RAMBlock *block; RAMBlock *last_block =3D NULL; @@ -1973,7 +1980,7 @@ static void ram_block_add(RAMBlock *new_block, Error = **errp) } else { new_block->host =3D qemu_anon_ram_alloc(new_block->max_length, &new_block->mr->align, - shared); + shared, noreserve); if (!new_block->host) { error_setg_errno(errp, errno, "cannot set up guest memory '%s'", @@ -2045,7 +2052,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, int64_t file_size, file_align; =20 /* Just support these ram flags by now. */ - assert((ram_flags & ~(RAM_SHARED | RAM_PMEM)) =3D=3D 0); + assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE)) =3D=3D 0= ); =20 if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); @@ -2137,6 +2144,8 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ra= m_addr_t max_size, Error *local_err =3D NULL; =20 assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) =3D= =3D 0); + assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC | + RAM_NORESERVE)) =3D=3D 0); assert(!host ^ (ram_flags & RAM_PREALLOC)); =20 size =3D HOST_PAGE_ALIGN(size); @@ -2170,7 +2179,7 @@ RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, vo= id *host, RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { - assert((ram_flags & ~RAM_SHARED) =3D=3D 0); + assert((ram_flags & ~(RAM_SHARED | RAM_NORESERVE)) =3D=3D 0); return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, = errp); } =20 diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 1ddc0e2a1e..d0cf4aaee5 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu/mmap-alloc.h" #include "qemu/host-utils.h" +#include "qemu/error-report.h" =20 #define HUGETLBFS_MAGIC 0x958458f6 =20 @@ -121,6 +122,7 @@ static void *mmap_reserve(size_t size, int fd) static void *mmap_activate(void *ptr, size_t size, int fd, uint32_t qemu_map_flags, off_t map_offset) { + const bool noreserve =3D qemu_map_flags & QEMU_MAP_NORESERVE; const bool readonly =3D qemu_map_flags & QEMU_MAP_READONLY; const bool shared =3D qemu_map_flags & QEMU_MAP_SHARED; const bool sync =3D qemu_map_flags & QEMU_MAP_SYNC; @@ -129,6 +131,11 @@ static void *mmap_activate(void *ptr, size_t size, int= fd, int flags =3D MAP_FIXED; void *activated_ptr; =20 + if (noreserve) { + error_report("Skipping reservation of swap space is not supported"= ); + return MAP_FAILED; + } + flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; if (shared && sync) { diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 0dd7784a88..e8bdb02e1d 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -227,9 +227,11 @@ void *qemu_memalign(size_t alignment, size_t size) } =20 /* alloc shared memory pages */ -void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) +void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared, + bool noreserve) { - const uint32_t qemu_map_flags =3D shared ? QEMU_MAP_SHARED : 0; + const uint32_t qemu_map_flags =3D (shared ? QEMU_MAP_SHARED : 0) | + (noreserve ? QEMU_MAP_NORESERVE : 0); size_t align =3D QEMU_VMALLOC_ALIGN; void *ptr =3D qemu_ram_mmap(-1, size, align, qemu_map_flags, 0); =20 diff --git a/util/oslib-win32.c b/util/oslib-win32.c index ca99356fdf..ee3a3692d8 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -38,6 +38,7 @@ #include "trace.h" #include "qemu/sockets.h" #include "qemu/cutils.h" +#include "qemu/error-report.h" #include =20 /* this must come after including "trace.h" */ @@ -76,10 +77,20 @@ static int get_allocation_granularity(void) return system_info.dwAllocationGranularity; } =20 -void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared) +void *qemu_anon_ram_alloc(size_t size, uint64_t *align, bool shared, + bool noreserve) { void *ptr; =20 + if (noreserve) { + /* + * We need a MEM_COMMIT before accessing any memory in a MEM_RESER= VE + * area; we cannot easily mimic POSIX MAP_NORESERVE semantics. + */ + error_report("Skipping reservation of swap space is not supported.= "); + return NULL; + } + ptr =3D VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); trace_qemu_anon_ram_alloc(size, ptr); =20 --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765467378338.71098072837435; Tue, 15 Jun 2021 06:57:47 -0700 (PDT) Received: from localhost ([::1]:35520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Za-0001aR-8C for importer2@patchew.org; Tue, 15 Jun 2021 09:57:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hu-0006D4-AL for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:41604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hq-0002qw-CR for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:29 -0400 Received: by mail-ej1-x62b.google.com with SMTP id ho18so22647230ejc.8 for ; Tue, 15 Jun 2021 06:39:22 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZLzJz6mvcZ5l6J2g/diF/Ob1Evu0mnWqFDyz0vggPgc=; b=WoA5nsyq//3QDBStXdozyikONdL1Zy/VO9tZ89c9r9U2zGkRXHHHfsGOxCb1gbKnHj zd6YnhQbkgKJFlccee4IkhE+Tpms9MJODZVufyZHKcsmFT21aJCZnu7meTTDs829mWpw ncQxCdTGKbmlpA3HbNVogXAMKCiqNkUzqABaRoGBCDrkkj/14Bn8k8PSlihH9ofei8Pi XcvGgcEC/erMVzLG+WzicA2Lz2HzLbfSNk2ws4BueRCNj8Ok8EI9geP9fNtueGjtXKHQ GYaQKMtF8v/dfMDIiVjVlligL9lT87/z0gi/iRHxF9YqGI2DNqXjGw9dyxKXAK8KHOU7 VAdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ZLzJz6mvcZ5l6J2g/diF/Ob1Evu0mnWqFDyz0vggPgc=; b=LWWFvgRtTsIDMSl02rU4FMK/CMVUDm8XkpWHpGXMIo0KSYfvXlOiurp5me9cYi087S pAjTKd8myW0UrrvNetFJCbDzTNA85SzX72F5oNFiBRrRkcisK/2WASHPGMiiPVhI0SS1 RKdwD9uaiueVNkXtHZgd1reDaazRTIymUBmfEhfnMNKvqH6XB+4e37uGMsV7v6mYtg5R +3ld8zc7k072rmIouGBHuoZhMVqMDm3/IZ4Nq1TCNDXNz1hPBhOVl1Hzzv9Z7HKStkZ6 4qdE80Kj0u2CMZIQLhx28MBPFNnbd7OZ8tZDd8EVo8GwWKr11/tFysVI8l98ZIZprwWT LCxw== X-Gm-Message-State: AOAM53156mzvYiNVnvFmgUcIauA0kgoLp4arg9lr+gz5+F/nNogvphOe pf7IGKkc5fj0ETL/t5rbEeUeLQq8VVQ= X-Google-Smtp-Source: ABdhPJx5FftY8OeDh/F5r/g+xhxTdV8mAxSwMVdVR/4W+tJ70jUzVMofbvEX4vVzolT84d1l9vq4bg== X-Received: by 2002:a17:906:b191:: with SMTP id w17mr21430546ejy.10.1623764361667; Tue, 15 Jun 2021 06:39:21 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 26/33] util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux Date: Tue, 15 Jun 2021 15:38:48 +0200 Message-Id: <20210615133855.775687-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's support RAM_NORESERVE via MAP_NORESERVE on Linux. The flag has no effect on most shared mappings - except for hugetlbfs and anonymous memory. Linux man page: "MAP_NORESERVE: Do not reserve swap space for this mapping. When swap space is reserved, one has the guarantee that it is possible to modify the mapping. When swap space is not reserved one might get SIGSEGV upon a write if no physical memory is available. See also the discussion of the file /proc/sys/vm/overcommit_memory in proc(5). In kernels before 2.6, this flag had effect only for private writable mappings." Note that the "guarantee" part is wrong with memory overcommit in Linux. Also, in Linux hugetlbfs is treated differently - we configure reservation of huge pages from the pool, not reservation of swap space (huge pages cannot be swapped). The rough behavior is [1]: a) !Hugetlbfs: 1) Without MAP_NORESERVE *or* with memory overcommit under Linux disabled ("/proc/sys/vm/overcommit_memory =3D=3D 2"), the following accounting/reservation happens: For a file backed map SHARED or READ-only - 0 cost (the file is the map not swap) PRIVATE WRITABLE - size of mapping per instance For an anonymous or /dev/zero map SHARED - size of mapping PRIVATE READ-only - 0 cost (but of little use) PRIVATE WRITABLE - size of mapping per instance 2) With MAP_NORESERVE, no accounting/reservation happens. b) Hugetlbfs: 1) Without MAP_NORESERVE, huge pages are reserved. 2) With MAP_NORESERVE, no huge pages are reserved. Note: With "/proc/sys/vm/overcommit_memory =3D=3D 0", we were already able to configure it for !hugetlbfs globally; this toggle now allows configuring it more fine-grained, not for the whole system. The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. [1] https://www.kernel.org/doc/Documentation/vm/overcommit-accounting Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and mach= ine core Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-10-david@redhat.com> Signed-off-by: Paolo Bonzini --- include/qemu/osdep.h | 3 ++ softmmu/physmem.c | 1 + util/mmap-alloc.c | 69 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 38a3327db9..488d8a4955 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -195,6 +195,9 @@ extern "C" { #ifndef MAP_FIXED_NOREPLACE #define MAP_FIXED_NOREPLACE 0 #endif +#ifndef MAP_NORESERVE +#define MAP_NORESERVE 0 +#endif #ifndef ENOMEDIUM #define ENOMEDIUM ENODEV #endif diff --git a/softmmu/physmem.c b/softmmu/physmem.c index a7725d8474..bf5493eab0 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2251,6 +2251,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t lengt= h) flags =3D MAP_FIXED; flags |=3D block->flags & RAM_SHARED ? MAP_SHARED : MAP_PRIVATE; + flags |=3D block->flags & RAM_NORESERVE ? MAP_NORESERVE : = 0; if (block->fd >=3D 0) { area =3D mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, block->fd, offset); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index d0cf4aaee5..838e286ce5 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -20,6 +20,7 @@ #include "qemu/osdep.h" #include "qemu/mmap-alloc.h" #include "qemu/host-utils.h" +#include "qemu/cutils.h" #include "qemu/error-report.h" =20 #define HUGETLBFS_MAGIC 0x958458f6 @@ -83,6 +84,70 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return qemu_real_host_page_size; } =20 +#define OVERCOMMIT_MEMORY_PATH "/proc/sys/vm/overcommit_memory" +static bool map_noreserve_effective(int fd, uint32_t qemu_map_flags) +{ +#if defined(__linux__) + const bool readonly =3D qemu_map_flags & QEMU_MAP_READONLY; + const bool shared =3D qemu_map_flags & QEMU_MAP_SHARED; + gchar *content =3D NULL; + const char *endptr; + unsigned int tmp; + + /* + * hugeltb accounting is different than ordinary swap reservation: + * a) Hugetlb pages from the pool are reserved for both private and + * shared mappings. For shared mappings, all mappers have to specify + * MAP_NORESERVE. + * b) MAP_NORESERVE is not affected by /proc/sys/vm/overcommit_memory. + */ + if (qemu_fd_getpagesize(fd) !=3D qemu_real_host_page_size) { + return true; + } + + /* + * Accountable mappings in the kernel that can be affected by MAP_NORE= SEVE + * are private writable mappings (see mm/mmap.c:accountable_mapping() = in + * Linux). For all shared or readonly mappings, MAP_NORESERVE is always + * implicitly active -- no reservation; this includes shmem. The only + * exception is shared anonymous memory, it is accounted like private + * anonymous memory. + */ + if (readonly || (shared && fd >=3D 0)) { + return true; + } + + /* + * MAP_NORESERVE is globally ignored for applicable !hugetlb mappings = when + * memory overcommit is set to "never". Sparse memory regions aren't r= eally + * possible in this system configuration. + * + * Bail out now instead of silently committing way more memory than + * currently desired by the user. + */ + if (g_file_get_contents(OVERCOMMIT_MEMORY_PATH, &content, NULL, NULL) = && + !qemu_strtoui(content, &endptr, 0, &tmp) && + (!endptr || *endptr =3D=3D '\n')) { + if (tmp =3D=3D 2) { + error_report("Skipping reservation of swap space is not suppor= ted:" + " \"" OVERCOMMIT_MEMORY_PATH "\" is \"2\""); + return false; + } + return true; + } + /* this interface has been around since Linux 2.6 */ + error_report("Skipping reservation of swap space is not supported:" + " Could not read: \"" OVERCOMMIT_MEMORY_PATH "\""); + return false; +#endif + /* + * E.g., FreeBSD used to define MAP_NORESERVE, never implemented it, + * and removed it a while ago. + */ + error_report("Skipping reservation of swap space is not supported"); + return false; +} + /* * Reserve a new memory region of the requested size to be used for mapping * from the given fd (if any). @@ -131,13 +196,13 @@ static void *mmap_activate(void *ptr, size_t size, in= t fd, int flags =3D MAP_FIXED; void *activated_ptr; =20 - if (noreserve) { - error_report("Skipping reservation of swap space is not supported"= ); + if (noreserve && !map_noreserve_effective(fd, qemu_map_flags)) { return MAP_FAILED; } =20 flags |=3D fd =3D=3D -1 ? MAP_ANONYMOUS : 0; flags |=3D shared ? MAP_SHARED : MAP_PRIVATE; + flags |=3D noreserve ? MAP_NORESERVE : 0; if (shared && sync) { map_sync_flags =3D MAP_SYNC | MAP_SHARED_VALIDATE; } --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623766164859394.894804666033; Tue, 15 Jun 2021 07:09:24 -0700 (PDT) Received: from localhost ([::1]:40472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9kq-00074x-3M for importer2@patchew.org; Tue, 15 Jun 2021 10:09:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hs-00069G-F2 for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:28 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:34656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Ho-0002r0-LK for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:27 -0400 Received: by mail-ej1-x634.google.com with SMTP id g8so22657202ejx.1 for ; Tue, 15 Jun 2021 06:39:23 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kr3IPZIn3YY4xCSnEba8QHvPCHxkDg0ZjFV9NHyZrb8=; b=rWdPaXv0Nzd5vfROXMGhsQGHfjHF4eBQ+f1+CzOCV7wwiOSyszYuww15PnF+F2KgXs UPttz1vOcFA3RFySTN2AylO2uJYgFcbavOCpPN9d6o8ybGRyBnc87QstPGfWa7wwOihQ Y9Y2YB8rSC7UJSt5h0aBadckIpjmGJ+uMHYVejByjRvm/5E+XUzkN3ozs+zWGeCRETCy Ra5Z3JPkgvV9fZC4k03cvFPMMgFDSsBEFyVPGeUYWl84s5xb6ZKjq0oTFUtc+S+/tsgN C6UsPL3dPd9vrKk6e2DXOZR6XxCFif6QUXfrz9GKpm1xyVZu/s4LsooDL3fBGrWgClQc KjeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kr3IPZIn3YY4xCSnEba8QHvPCHxkDg0ZjFV9NHyZrb8=; b=uSQYZjQ6e21bek/mO4Suf7y1vidDeITHnw7j0N2XE7Wp1WSRsFq+FpLWMYJOC2sw8+ 0aBSnCaFattK9QpN+1z/lkafdXkfze8zdMQchOZ0UIaFXdS4jtVniec4/ddYmdNrdpcY V02qxcwoVePPKVcXc2ve+mMSRutUP/naW0Fp2b0pVXyFAyj/T+W7XpyxtZsIu+8vQivi zH46EOYOFmBlDSywEms/rmJe6/MDxRoD/FmrhvDuaJqvjCXEUIv1PLSPrBXPW9e7kckh RjS6j3zPxULw0rcTlt1mBNOkgVAIeVZGUSG4MACicFOEc5ONAEz8TpsIacbv/csXPAdY 694Q== X-Gm-Message-State: AOAM532LoQaFU2r7nSrs9SyvJvCI+t5nQMYuoUJQb1YBceXOqaO5VtOc Zj3lRrcwo7P7hrtdlrA/tR7C0WGniZU= X-Google-Smtp-Source: ABdhPJw1nj6rRcFjqF42T1KY7zn25oRjE/3yEECGIOPg+UjOlE5VGf9mic/BeiiRkUKHVix3Vj9c6g== X-Received: by 2002:a17:906:70c1:: with SMTP id g1mr14096628ejk.89.1623764362482; Tue, 15 Jun 2021 06:39:22 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 27/33] hostmem: Wire up RAM_NORESERVE via "reserve" property Date: Tue, 15 Jun 2021 15:38:49 +0200 Message-Id: <20210615133855.775687-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x634.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , Markus Armbruster , Peter Xu , Igor Mammedov , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's provide a way to control the use of RAM_NORESERVE via memory backends using the "reserve" property which defaults to true (old behavior). Only Linux currently supports clearing the flag (and support is checked at runtime, depending on the setting of "/proc/sys/vm/overcommit_memory"). Windows and other POSIX systems will bail out with "reserve=3Dfalse". The target use case is virtio-mem, which dynamically exposes memory inside a large, sparse memory area to the VM. This essentially allows avoiding to set "/proc/sys/vm/overcommit_memory =3D=3D 0") when using virtio-mem and also supporting hugetlbfs in the future. As really only Linux implements RAM_NORESERVE right now, let's expose the property only with CONFIG_LINUX. Setting the property to "false" will then only fail in corner cases -- for example on very old kernels or when memory overcommit was completely disabled by the admin. Reviewed-by: Peter Xu Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Markus Armbruster Cc: Eric Blake Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-11-david@redhat.com> Signed-off-by: Paolo Bonzini --- backends/hostmem-file.c | 11 ++++++----- backends/hostmem-memfd.c | 1 + backends/hostmem-ram.c | 1 + backends/hostmem.c | 36 ++++++++++++++++++++++++++++++++++++ include/sysemu/hostmem.h | 2 +- qapi/qom.json | 10 ++++++++++ 6 files changed, 55 insertions(+), 6 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 9b1b9f0a56..cd038024fa 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -39,6 +39,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Err= or **errp) object_get_typename(OBJECT(backend))); #else HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(backend); + uint32_t ram_flags; gchar *name; =20 if (!backend->size) { @@ -51,11 +52,11 @@ file_backend_memory_alloc(HostMemoryBackend *backend, E= rror **errp) } =20 name =3D host_memory_backend_get_name(backend); - memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), - name, - backend->size, fb->align, - (backend->share ? RAM_SHARED : 0) | - (fb->is_pmem ? RAM_PMEM : 0), + ram_flags =3D backend->share ? RAM_SHARED : 0; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |=3D fb->is_pmem ? RAM_PMEM : 0; + memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), name, + backend->size, fb->align, ram_flags, fb->mem_path, fb->readonly, errp); g_free(name); #endif diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c index 3076da146d..3fc85c3db8 100644 --- a/backends/hostmem-memfd.c +++ b/backends/hostmem-memfd.c @@ -54,6 +54,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Er= ror **errp) =20 name =3D host_memory_backend_get_name(backend); ram_flags =3D backend->share ? RAM_SHARED : 0; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name, backend->size, ram_flags, fd, 0, errp); g_free(name); diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c index 741e701062..b8e55cdbd0 100644 --- a/backends/hostmem-ram.c +++ b/backends/hostmem-ram.c @@ -29,6 +29,7 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Erro= r **errp) =20 name =3D host_memory_backend_get_name(backend); ram_flags =3D backend->share ? RAM_SHARED : 0; + ram_flags |=3D backend->reserve ? 0 : RAM_NORESERVE; memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), = name, backend->size, ram_flags, errp); g_free(name); diff --git a/backends/hostmem.c b/backends/hostmem.c index aab3de8408..4c05862ed5 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -216,6 +216,11 @@ static void host_memory_backend_set_prealloc(Object *o= bj, bool value, Error *local_err =3D NULL; HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); =20 + if (!backend->reserve && value) { + error_setg(errp, "'prealloc=3Don' and 'reserve=3Doff' are incompat= ible"); + return; + } + if (!host_memory_backend_mr_inited(backend)) { backend->prealloc =3D value; return; @@ -267,6 +272,7 @@ static void host_memory_backend_init(Object *obj) /* TODO: convert access to globals to compat properties */ backend->merge =3D machine_mem_merge(machine); backend->dump =3D machine_dump_guest_core(machine); + backend->reserve =3D true; backend->prealloc_threads =3D 1; } =20 @@ -425,6 +431,30 @@ static void host_memory_backend_set_share(Object *o, b= ool value, Error **errp) backend->share =3D value; } =20 +#ifdef CONFIG_LINUX +static bool host_memory_backend_get_reserve(Object *o, Error **errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + + return backend->reserve; +} + +static void host_memory_backend_set_reserve(Object *o, bool value, Error *= *errp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + + if (host_memory_backend_mr_inited(backend)) { + error_setg(errp, "cannot change property value"); + return; + } + if (backend->prealloc && !value) { + error_setg(errp, "'prealloc=3Don' and 'reserve=3Doff' are incompat= ible"); + return; + } + backend->reserve =3D value; +} +#endif /* CONFIG_LINUX */ + static bool host_memory_backend_get_use_canonical_path(Object *obj, Error **errp) { @@ -493,6 +523,12 @@ host_memory_backend_class_init(ObjectClass *oc, void *= data) host_memory_backend_get_share, host_memory_backend_set_share); object_class_property_set_description(oc, "share", "Mark the memory as private to QEMU or shared"); +#ifdef CONFIG_LINUX + object_class_property_add_bool(oc, "reserve", + host_memory_backend_get_reserve, host_memory_backend_set_reserve); + object_class_property_set_description(oc, "reserve", + "Reserve swap space (or huge pages) if applicable"); +#endif /* CONFIG_LINUX */ /* * Do not delete/rename option. This option must be considered stable * (as if it didn't have the 'x-' prefix including deprecation period)= as diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index df5644723a..9ff5c16963 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -64,7 +64,7 @@ struct HostMemoryBackend { /* protected */ uint64_t size; bool merge, dump, use_canonical_path; - bool prealloc, is_mapped, share; + bool prealloc, is_mapped, share, reserve; uint32_t prealloc_threads; DECLARE_BITMAP(host_nodes, MAX_NODES + 1); HostMemPolicy policy; diff --git a/qapi/qom.json b/qapi/qom.json index f7ef30f940..652be317b8 100644 --- a/qapi/qom.json +++ b/qapi/qom.json @@ -545,6 +545,9 @@ # @share: if false, the memory is private to QEMU; if true, it is shared # (default: false) # +# @reserve: if true, reserve swap space (or huge pages) if applicable +# (default: true) (since 6.1) +# # @size: size of the memory region in bytes # # @x-use-canonical-path-for-ramblock-id: if true, the canoncial path is us= ed @@ -556,6 +559,12 @@ # false generally, but true for mac= hine # types <=3D 4.0) # +# Note: prealloc=3Dtrue and reserve=3Dfalse cannot be set at the same time= . With +# reserve=3Dtrue, the behavior depends on the operating system: for = example, +# Linux will not reserve swap space for shared file mappings -- +# "not applicable". In contrast, reserve=3Dfalse will bail out if it= cannot +# be configured accordingly. +# # Since: 2.1 ## { 'struct': 'MemoryBackendProperties', @@ -566,6 +575,7 @@ '*prealloc': 'bool', '*prealloc-threads': 'uint32', '*share': 'bool', + '*reserve': 'bool', 'size': 'size', '*x-use-canonical-path-for-ramblock-id': 'bool' } } =20 --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162376539184351.07545065114982; Tue, 15 Jun 2021 06:56:31 -0700 (PDT) Received: from localhost ([::1]:59634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9YM-0007IT-NX for importer2@patchew.org; Tue, 15 Jun 2021 09:56:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hu-0006D5-As for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]:33341) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hq-0002r5-80 for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:29 -0400 Received: by mail-ej1-x631.google.com with SMTP id g20so22743799ejt.0 for ; Tue, 15 Jun 2021 06:39:24 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p85ZwP5+cUhD9A/9yct5lXRRYxAcgJOgoRto1Cj2xZA=; b=pmjHxYVSZzLc/tQA7hCxQh+BlT4n6vmLRO0T4mYdrGnUBIU+fK9mcxSHEuc8KMvMjC R6Vo/13sqgQbQCcUN5AT/U2dvblZqa8Pbg0Z8CVdr8zhP6eK8mHxcdbweQXiKErNRjhF GisvrKru9K2YbKuroevRUGvKWh9XJhxMutofLYtVXq51zmY6uQsZuWLQ1R7m9YLGGLmU pBK6PRUQkyhECrFXNmEuT/XsL5Vzk/d2FwTPHz6WJ11wG72kwhk+46eBrA/Tbn169Tn1 YaSMQ5UTTqs3xMl8+qkZEe1Ztxfr3NIY9/P9WTpyzXg/ArnP8+J/0TNqP9qO6JEYAQVV 95aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=p85ZwP5+cUhD9A/9yct5lXRRYxAcgJOgoRto1Cj2xZA=; b=LzJASJ5leIOT3LtiAC5/qZ2fTMtxbc+pAeIRarIM095dy2dWKjKypgL4lF3T3NEqtL DXvr4DNngqigWOAYglYE9/qZLhsYu4e9OH5HZ6w84WzIevi3MSCDUvJd0cf/Bkl98hMr KPchfQp8LUXVSgom5tx8YOyDKhwObJh3mfGbRrDRumtca+FW7NjfX9zss98+ZXAXxNKJ QJofO8wujzy2oPR3FKJi8jEr6LOyTpMicmn6ik+bzAbaExXsUy2CAMPsG6f47xD4glSO XEoRX3JTxtu/H2SSZH23xVXjEG3lYyX6nEU3ZjgbcJefv1ZZ97kefSrabYiO2zoTqS9Z MJfQ== X-Gm-Message-State: AOAM533cDUMxdo4T3/NBZRLYG2z6/4OJlBkFpHnniY7SBsCgF0rv9ipl clkI7WzaG7PKKLwyubJ74R7LRgN/TrM= X-Google-Smtp-Source: ABdhPJyABa6mmbL1YrWwoAOYX5kRzQiXyN1TujD3DplViU/lcqXzZHTUvbNh0QKhqEwoURwuyDQhIQ== X-Received: by 2002:a17:906:8041:: with SMTP id x1mr20374484ejw.81.1623764363250; Tue, 15 Jun 2021 06:39:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 28/33] qmp: Clarify memory backend properties returned via query-memdev Date: Tue, 15 Jun 2021 15:38:50 +0200 Message-Id: <20210615133855.775687-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::631; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x631.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , Eric Blake , Markus Armbruster , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand We return information on the currently configured memory backends and don't configure them, so decribe what the currently set properties express. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Suggested-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Eric Blake Cc: Markus Armbruster Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-12-david@redhat.com> Signed-off-by: Paolo Bonzini --- qapi/machine.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qapi/machine.json b/qapi/machine.json index 58a9c86b36..eb14364819 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -790,11 +790,11 @@ # # @size: memory backend size # -# @merge: enables or disables memory merge support +# @merge: whether memory merge support is enabled # -# @dump: includes memory backend's memory in a core dump or not +# @dump: whether memory backend's memory is included in a core dump # -# @prealloc: enables or disables memory preallocation +# @prealloc: whether memory was preallocated # # @host-nodes: host nodes for its memory policy # --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623766369694171.63466684427726; Tue, 15 Jun 2021 07:12:49 -0700 (PDT) Received: from localhost ([::1]:49048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9o8-0004iJ-VR for importer2@patchew.org; Tue, 15 Jun 2021 10:12:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hu-0006Cv-9V for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:36682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hq-0002rB-6t for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:29 -0400 Received: by mail-ej1-x62c.google.com with SMTP id nd37so14905521ejc.3 for ; Tue, 15 Jun 2021 06:39:24 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xr8JhkOLb64+1jwZzCOyibuOvNn/q3bYsD1RfjM0chQ=; b=LmTHkLxI/4nSCFOyEXwcEpXWkOMP3YmN/xe11WhrRXgr8qPjgXYX24dZqt8g8acg3K C796VfF0p2FVqoJ/KzOr7B8c4RDSVP+qK5EiG4wdCi/1QcpijXe//7WS6v4wm5q/nUqB vpSggR0oQBzqFDdu8PV08G9ie3KqowxgT1W/gJJmUsgdrQdHwf5SiJOCUgw1dqrC04I2 rVnjc/Jb0veZ+Wldo+EyMD9CLvmYl1a2Mu7so1mPDwPVKZ49fmA7jt7xikv0d7jMQl/S 0CP+3XcB8tTZjs+1uea91lJTgdmnEg+IpQPFichnm/hvHadbWwAX1571Li6G/kPKgmAV EWsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Xr8JhkOLb64+1jwZzCOyibuOvNn/q3bYsD1RfjM0chQ=; b=heeUC5Ljkc+Srb89QKIBHql32jqJWa5wU6atLarTNUtTt3QjJuwtxWA6zgSM0MLzYC 6//XESZAuKQ+vs0PwWVCwl0ij9UKwn8EePlTgIj9ZcxuPumkIQggD06iL3Cp+IdC+qXL nbBqV9Ma5ghIvZ1m0wjBNwdvbnVQm11E+xuT8/N4SwIC2DZZ0OFBFy32MfEg6fkrr1Q2 KU+AFvcBXqyj8SmpxwcBBPb4Ra4fgREANxyI5HNZOYhCgFRyvbJF0hxy1tMenMPOsvRT DfUtf3MhJi/zEhe8OalAi7yIKijVV012C1jT2zm6hMvIgjjCD6PDfdTZYejGaD8Q4GzA 2yMw== X-Gm-Message-State: AOAM531EP/uKa6oi/opxkk/49fdBrvJvQzlgWbwndE/uTDpLYgQoNKkn IVCy1WEGeUOmhBmm/hmhOHZdXvYWAuE= X-Google-Smtp-Source: ABdhPJy6G1tr0kBX89FFsiHn3ENWu6/xnC4D0jWEkOnKG3Ju1o/ZOv25Z367u0jjW3auZ41YmQ+zHQ== X-Received: by 2002:a17:906:7c4d:: with SMTP id g13mr21052942ejp.216.1623764364081; Tue, 15 Jun 2021 06:39:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 29/33] qmp: Include "share" property of memory backends Date: Tue, 15 Jun 2021 15:38:51 +0200 Message-Id: <20210615133855.775687-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , Eric Blake , Markus Armbruster , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's include the property, which can be helpful when debugging, for example, to spot misuse of MAP_PRIVATE which can result in some ugly corner cases (e.g., double-memory consumption on shmem). Use the same description we also use for describing the property. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Eric Blake Cc: Markus Armbruster Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-13-david@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/machine-qmp-cmds.c | 1 + qapi/machine.json | 3 +++ 2 files changed, 4 insertions(+) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index a36c96608f..a36ceaf4f3 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -172,6 +172,7 @@ static int query_memdev(Object *obj, void *opaque) m->merge =3D object_property_get_bool(obj, "merge", &error_abort); m->dump =3D object_property_get_bool(obj, "dump", &error_abort); m->prealloc =3D object_property_get_bool(obj, "prealloc", &error_a= bort); + m->share =3D object_property_get_bool(obj, "share", &error_abort); m->policy =3D object_property_get_enum(obj, "policy", "HostMemPoli= cy", &error_abort); host_nodes =3D object_property_get_qobject(obj, diff --git a/qapi/machine.json b/qapi/machine.json index eb14364819..1395742a4a 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -796,6 +796,8 @@ # # @prealloc: whether memory was preallocated # +# @share: whether memory is private to QEMU or shared (since 6.1) +# # @host-nodes: host nodes for its memory policy # # @policy: memory policy of memory backend @@ -809,6 +811,7 @@ 'merge': 'bool', 'dump': 'bool', 'prealloc': 'bool', + 'share': 'bool', 'host-nodes': ['uint16'], 'policy': 'HostMemPolicy' }} =20 --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765540333348.43345570358076; Tue, 15 Jun 2021 06:59:00 -0700 (PDT) Received: from localhost ([::1]:39960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9al-0004YN-6A for importer2@patchew.org; Tue, 15 Jun 2021 09:58:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hv-0006DB-J7 for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:39922) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hs-0002s7-0M for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:30 -0400 Received: by mail-ej1-x62b.google.com with SMTP id l1so22571011ejb.6 for ; Tue, 15 Jun 2021 06:39:25 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+EFladb3eqe0vt+VFB7TILa1exqZV921bqMeigXL0sY=; b=Teuw6AyrzF9Q6H2ApR8gtN0HTWnFui/lCx7SOzpTww1LkSiaISYpm/vzd7FBvclvSE LJH9M+FKfEHx3EsObnyU2TOJL4iHRl0h64lxdm6y55a/VpH46dN37XpFTZOYS4h3SKe/ Z8f31Wik9/ZQH5rwv4f7gFpcC08cvqCikVr8hg12teFY+juSylxLhP0W8yMr7WaNJCth bBEIYXLiCsntVQJ3zNvNoQreoHEh0bp4fYAoU9EG2cVFoVoWc52+avpOQvjstewoTi1e NA5OoNTF/fCu+W5JvysXCdl6bUjTyuQZYBr2T9VuRRfj0n1EcvfyD0XYVzPcRp1ywTCb WMkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+EFladb3eqe0vt+VFB7TILa1exqZV921bqMeigXL0sY=; b=oHmsZTooM3Q6+loDTTwk3SNdouvpaZxcxHqQzYJdQOqMBci9L2UQxALvX+cMY3+o8F IvdwRSX7LbMTi3AiNuZDD1GaFa0+umq7bhCaJxQozK0LsU3nARg/VAIsV/vKQKk4AQqh SuoGnKzRZ/aW5mZIFnCBgy8KcxkNyk1tzPcdVoOBjifVft9bAGo1VGy961z5vTF+frwQ x/Q4LNWVLz2LboN+du6K6tZaw6848S/8LEcvgoTn8GIdzp02FuCY2bPcwLQnsq7h82qh anLQbhh6UQiZLeAfKim7aUdIq3e5fsPi81+nxEdEEoVot160P6mt9Ct9XLeX1UZugzrk WF4A== X-Gm-Message-State: AOAM530HqMXhZC3v0O6g5V0CokEA6B6RMkw79LrycJ8zmR8mjwz38kW8 hZrNkHpny39ZEcfL1dGxFM+KiyKlnaU= X-Google-Smtp-Source: ABdhPJww8Dq98qXjqvnSLkqJNWsIiSR+D2OjESwXbRaZXEdgMa5+7LCfLbo4PD/4TeuHUMZbp41uWQ== X-Received: by 2002:a17:907:2bfa:: with SMTP id gv58mr2887690ejc.529.1623764364968; Tue, 15 Jun 2021 06:39:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 30/33] hmp: Print "share" property of memory backends with "info memdev" Date: Tue, 15 Jun 2021 15:38:52 +0200 Message-Id: <20210615133855.775687-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62b.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , "Dr . David Alan Gilbert" , Igor Mammedov , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's print the property. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Markus Armbruster Cc: Eric Blake Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-14-david@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/machine-hmp-cmds.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c index 58248cffa3..004a92b3d6 100644 --- a/hw/core/machine-hmp-cmds.c +++ b/hw/core/machine-hmp-cmds.c @@ -110,6 +110,8 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) m->value->dump ? "true" : "false"); monitor_printf(mon, " prealloc: %s\n", m->value->prealloc ? "true" : "false"); + monitor_printf(mon, " share: %s\n", + m->value->share ? "true" : "false"); monitor_printf(mon, " policy: %s\n", HostMemPolicy_str(m->value->policy)); visit_complete(v, &str); --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765715061564.5643258356948; Tue, 15 Jun 2021 07:01:55 -0700 (PDT) Received: from localhost ([::1]:48400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9dY-0001oG-9Y for importer2@patchew.org; Tue, 15 Jun 2021 10:01:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hv-0006DA-JV for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:43871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hs-0002sE-4v for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: by mail-ej1-x62d.google.com with SMTP id nb6so2472155ejc.10 for ; Tue, 15 Jun 2021 06:39:26 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mwlb91Bq0n0L0KzBlNI9L4RP30x6/A2tSce+bkWzLWw=; b=u0ni/tplNLkkEZQVdqH2h6e1Um/O2k9L/c+XbQ+rG7a42lDlhAjm5y8Rk7gaLKzMD0 U7uNCNNKgzJnK0K5WIsEYqbLLRSQe7Ru04zAgXLnNlwXpOQ2KMvvu0uNo5DT0Esf5A31 RBsFQau8T+Eeh+C5d+5Qxw6M27PW2H3EmXWV/lFZ2NrJCdywnxlc++7pmS4op11LdR/6 zcWN3rDz/5VG8OasBRsEvG2q0MHCCRRrDYIj5u7bZ62B6kkfxtVpzonK5y54sVziYJio KFNJ8swWPymW6I9AaHEsZ3Fy3OEZWeEfyc9kuCn2RhBHrakPD/ugMWeHU7wcj3gikPt5 8O8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Mwlb91Bq0n0L0KzBlNI9L4RP30x6/A2tSce+bkWzLWw=; b=EAr8INgl38NUTKDII6+zQkwjdZjtoxrY/kzfyzaXfEuPXwc7sthu8TfpOkkeIZxX9D T/cO8esAQkJxfd6bvdS0oLvQxQtYvq1jwwHzfRQypEPRN1ptyBUBVK2CC7XjNrPvAnrb U52qy+zXaBpcVcmeu6oQa/GEnl4B4tRnKKiH6VXjfv6mSiqgBBh7AFtmhWCIcaOrXUCo EFLzx8TFdlQS0Hsr1gt93pC5nlk1/YZAKvaUY22pJI2RFRAAZ9/2RfHdhT1ntAu3kqhX nXkhRKDRT7DxJzsKrM3aXThrEjTfZDPUHZJcsE6DQqOyb2u4gJUxfae5fjA8q4bdYynf jXQg== X-Gm-Message-State: AOAM532Yt2qbe2RmoxF9VURZOEi+zHTCNQjKy4KlObRIPB/ZpRxCPsoT 3regYf3Ik2rRPvdVLf2QVQMH3jHMWcc= X-Google-Smtp-Source: ABdhPJwZ6tDDj18T0Ago+BwqEUsb/OqYbrAjC60PCJL5xf6oCWrdq22fqVE3K9WtXir9c2aSVIkLnQ== X-Received: by 2002:a17:906:33c8:: with SMTP id w8mr21328756eja.46.1623764365834; Tue, 15 Jun 2021 06:39:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 31/33] qmp: Include "reserve" property of memory backends Date: Tue, 15 Jun 2021 15:38:53 +0200 Message-Id: <20210615133855.775687-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62d.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , Eric Blake , Markus Armbruster , Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's include the new property. Instead of relying on CONFIG_LINUX, let's try to unconditionally grab the property and treat errors as "does not exist". Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Eric Blake Cc: Markus Armbruster Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-15-david@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/machine-qmp-cmds.c | 7 +++++++ qapi/machine.json | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/hw/core/machine-qmp-cmds.c b/hw/core/machine-qmp-cmds.c index a36ceaf4f3..216fdfaf3a 100644 --- a/hw/core/machine-qmp-cmds.c +++ b/hw/core/machine-qmp-cmds.c @@ -157,6 +157,7 @@ void qmp_set_numa_node(NumaOptions *cmd, Error **errp) =20 static int query_memdev(Object *obj, void *opaque) { + Error *err =3D NULL; MemdevList **list =3D opaque; Memdev *m; QObject *host_nodes; @@ -173,6 +174,12 @@ static int query_memdev(Object *obj, void *opaque) m->dump =3D object_property_get_bool(obj, "dump", &error_abort); m->prealloc =3D object_property_get_bool(obj, "prealloc", &error_a= bort); m->share =3D object_property_get_bool(obj, "share", &error_abort); + m->reserve =3D object_property_get_bool(obj, "reserve", &err); + if (err) { + error_free_or_abort(&err); + } else { + m->has_reserve =3D true; + } m->policy =3D object_property_get_enum(obj, "policy", "HostMemPoli= cy", &error_abort); host_nodes =3D object_property_get_qobject(obj, diff --git a/qapi/machine.json b/qapi/machine.json index 1395742a4a..e4d0f9b24f 100644 --- a/qapi/machine.json +++ b/qapi/machine.json @@ -798,6 +798,12 @@ # # @share: whether memory is private to QEMU or shared (since 6.1) # +# @reserve: whether swap space (or huge pages) was reserved if applicable. +# This corresponds to the user configuration and not the actual +# behavior implemented in the OS to perform the reservation. +# For example, Linux will never reserve swap space for shared +# file mappings. (since 6.1) +# # @host-nodes: host nodes for its memory policy # # @policy: memory policy of memory backend @@ -812,6 +818,7 @@ 'dump': 'bool', 'prealloc': 'bool', 'share': 'bool', + '*reserve': 'bool', 'host-nodes': ['uint16'], 'policy': 'HostMemPolicy' }} =20 --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765586443663.8034086839291; Tue, 15 Jun 2021 06:59:46 -0700 (PDT) Received: from localhost ([::1]:44152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9bV-0007Ky-Ag for importer2@patchew.org; Tue, 15 Jun 2021 09:59:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hv-0006D9-Iv for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:45869) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hs-0002st-4N for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:30 -0400 Received: by mail-ej1-x62c.google.com with SMTP id k7so22630441ejv.12 for ; Tue, 15 Jun 2021 06:39:27 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Us6ggabPs2Iu/tknvpN9PEYNzI6F+zr6OhgzB6XQ6h8=; b=O1uqAMFpZ2/XiGZNbHV3UMLT6bTeuSVdsjB4d5pvg8HuXg4WdNT/qojuPo8mjghq/7 izRbTbnvYDL4z5ySCsK9dsl9WuBciYOSCIN+unaoZPcojji6AIQYb0uWmLDJVj67s3+5 PuYIQWN4Vn2XgN8Eshui+r0cqO3kyzZtPbonaGsJZtrwJnCYJYpTxUoph1l+JRERfXIq +O5dV1InQaD15S3fvBEt9VwjtWGgqwm/WSuRNhSc2lvWIJXylK28THDvEkFKFtUuJOxk fQKugoSlIQCm6CYq/R+pL7LDlmxP5sfYC7+9Q0lF+zTu2GLNjt/ruzZ1kWM5koo1HP9A XTew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Us6ggabPs2Iu/tknvpN9PEYNzI6F+zr6OhgzB6XQ6h8=; b=dKNgla6X8tTW1ymd4EuUYtmyXrhNmPutLx8NYNi6GsU0lX6MRsITKBJPeF4iVxPGK0 CEf8HM85va7QlrMQjqTmuFjcBpsks7j2yOU3JS53R8HGJa6idmmXm3SeHo1tjIu1mXbB 5xdswxpVusC9yUCyAmAJgfYG78mAIlvWWV/rD975Z+ety+2FnNz77WHupEZj3LqL+H+X 8Z96tMIfyNLJG2X6v05Z8kHhJ+6iIwLe5LwoiRtm84Py0vtPABCjQX4XDV4dDUR1Ca6e w97PsgbK3neD/iFTwJxTBr3SaRzVuYhiV5zFBATOtm5kZWunheAG4KxGTYMRKQ8VRmz8 Q0QA== X-Gm-Message-State: AOAM530xqEy40ymJHYbSYZvyTCC4xTtT68yAnRCAzM3B7T0XGrxuMBqv 4M0XLCOPGUeKqaMyo2OeLxgEE9Walkw= X-Google-Smtp-Source: ABdhPJxmaaeCerAxi8ELxNKEcOIYlMoiMtTRAFU1g+wC/hVYIfvBeO4JveVZnOUcbyv+JL4M700Y6g== X-Received: by 2002:a17:906:26db:: with SMTP id u27mr21030296ejc.532.1623764366613; Tue, 15 Jun 2021 06:39:26 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 32/33] hmp: Print "reserve" property of memory backends with "info memdev" Date: Tue, 15 Jun 2021 15:38:54 +0200 Message-Id: <20210615133855.775687-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x62c.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , David Hildenbrand , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , "Dr . David Alan Gilbert" , Igor Mammedov , Eric Blake Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: David Hildenbrand Let's print the new property. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and mach= ine core Cc: Markus Armbruster Cc: Eric Blake Cc: Igor Mammedov Signed-off-by: David Hildenbrand Message-Id: <20210510114328.21835-16-david@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/machine-hmp-cmds.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/core/machine-hmp-cmds.c b/hw/core/machine-hmp-cmds.c index 004a92b3d6..76b22b00d6 100644 --- a/hw/core/machine-hmp-cmds.c +++ b/hw/core/machine-hmp-cmds.c @@ -112,6 +112,10 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict) m->value->prealloc ? "true" : "false"); monitor_printf(mon, " share: %s\n", m->value->share ? "true" : "false"); + if (m->value->has_reserve) { + monitor_printf(mon, " reserve: %s\n", + m->value->reserve ? "true" : "false"); + } monitor_printf(mon, " policy: %s\n", HostMemPolicy_str(m->value->policy)); visit_complete(v, &str); --=20 2.31.1 From nobody Sun May 5 07:41:59 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1623765238660849.4910712020478; Tue, 15 Jun 2021 06:53:58 -0700 (PDT) Received: from localhost ([::1]:50158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lt9Vt-0000qn-Id for importer2@patchew.org; Tue, 15 Jun 2021 09:53:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lt9Hv-0006E4-VK for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:32 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:43877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lt9Hs-0002sz-Gt for qemu-devel@nongnu.org; Tue, 15 Jun 2021 09:39:31 -0400 Received: by mail-ej1-x633.google.com with SMTP id nb6so2472295ejc.10 for ; Tue, 15 Jun 2021 06:39:28 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r17sm11843769edt.33.2021.06.15.06.39.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Jun 2021 06:39:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xuAPUpX6Hhq84IfvJMkUkq8FBAkzzJSj3GQD8rT6J7c=; b=KvbrcFyhGsSVgKH5uFyA1a2XVLH5X2sHtIzbb9AzDQnuYDH0m35VxXaQC+Mgzt8ZbG uH9/Q+J66wq9nTlfSX6DLJwdGR6qtFH/Lwfpa378LpB6Zf0Ue5hLTxi2Vc+gJXt+hl1+ jCFdPwbbCsQLsy0qV6w9s/L0bKukaAo4Mw+dkUtlaSeDmeKbfHFYHMhFW3PQqvR6B3Fk USSMsTq97Pq9tyXUzRPLTbBjVIlnyeYhccDY3F4onjCUOFzMWjRQEuMob3g21iqaFoH5 NuQTuG4AxJzVDGXZpxLQSUaxKr87Y8pHBKWGYWekNNxkIb0QHXa719fIfBq04cpaGhAU 4TDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=xuAPUpX6Hhq84IfvJMkUkq8FBAkzzJSj3GQD8rT6J7c=; b=JHGd4lc8m0hT1J8fYAL+D3IHznyoksrxbKJZRVDbqoEXeWTaPaVSLsh9tBg+g1x4KD e/biu1IFFsDe1dO1TjyNqx9vpuir4YQZ2E1ykgSlC3ivwsij1LFn6SobWMkWCUH0y2nL /LsQXCPBE/gY2s0IJv7MkDL1MsuVldJVKpjfoIopAQp0wHV/eltqv1+kSbuDx6f6SKlu 8CnxLvFnw4D0l6kydYlWyE8RCAPmTNcJnHTt+rtTQGZ0PTUmGfBl9pjprgo+gx/aEgjU IOzcDGA7FnCGYQaiRpMdmez/xbCL0cmzZVst9wxkU/x5tAl3nFy7TWmCW31aq6bTa9yQ lwzg== X-Gm-Message-State: AOAM533MdIjHV4Vb3MUvFk7xf0ON2kW4U3tnydCkIcXluDHnYo1sLVga 9rFB+HoPlEfWhDvSvuflI6iN+FCtuVE= X-Google-Smtp-Source: ABdhPJzBOJJF5irUwvvyr6alhCXJPUOk2YEd8+Q1gXKl7gNzuW3l9RzDRbDOg1oCD5FxfdfNrR2www== X-Received: by 2002:a17:906:b307:: with SMTP id n7mr20699397ejz.261.1623764367297; Tue, 15 Jun 2021 06:39:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 33/33] configure: map x32 to cpu_family x86_64 for meson Date: Tue, 15 Jun 2021 15:38:55 +0200 Message-Id: <20210615133855.775687-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615133855.775687-1-pbonzini@redhat.com> References: <20210615133855.775687-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=paolo.bonzini@gmail.com; helo=mail-ej1-x633.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Michael Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Michael The meson.build file defines supported_cpus which does not contain x32, and x32 is not one of meson's stable built-in values: https://mesonbuild.com/Reference-tables.html#cpu-families Signed-off-by: David Michael Message-Id: <878s3jrzm0.fsf@gmail.com> Signed-off-by: Paolo Bonzini --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 8dcb9965b2..4478f3889a 100755 --- a/configure +++ b/configure @@ -6384,7 +6384,7 @@ if test "$skip_meson" =3D no; then i386) echo "cpu_family =3D 'x86'" >> $cross ;; - x86_64) + x86_64|x32) echo "cpu_family =3D 'x86_64'" >> $cross ;; ppc64le) --=20 2.31.1