From patchwork Thu Jun 17 09:30:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4972FC2B9F4 for ; Thu, 17 Jun 2021 09:38:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5A206117A for ; Thu, 17 Jun 2021 09:38:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5A206117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoTb-0007uV-4r for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:38:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoN9-0002Yb-U4 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:39 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:33465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoN7-00060O-Mo for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:39 -0400 Received: by mail-ed1-x532.google.com with SMTP id d7so3135589edx.0 for ; Thu, 17 Jun 2021 02:31:36 -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=F0UOVti7/OyLA900wkR+I1Op/504hfGDIy8qDFTiso/oEQLCybThkCQ7wBRGnado7m BstKvo/ATmuygauuLKit6Rt8mym+7Se8U2aOQQvnwbYaTZ4YcaimKJz6ypKSn/T5ey4L VMIWZKK9cOxdpM8IpmIaloeEdYEh9kediEGtqOfMhsS6Ji8FSUr0ukJqh2DLHlW0JgVW peCBirZJOU49A/E60giANvxBMJL+BNlthK1f6BZWjf+pQfox6faS0GGsJS+XG5noYBAf zBgv/0tOQSHuTfJ2o9Nli10loemfOflBvCFzVbZKSKZgz24BAWCWtPA/CDWf+1mkLyR1 LZhw== 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=dcynj3WWum/dPy00L+qoqnwTAD87nUXafWva/Ts+ptEmQ01w0zJ+c9kmGcTJAol8T4 5SgOd8wzsUCZltw9YtvFT00f1gZ4jvsy4AF3TUqLV3Yeg2ejDol9GrEPJ9qyLeNNW5iy IEsiDShqHKaiJ3TQwhnIPUQ1UccRkYw7scS+uVRlOFkJJYfS6/CVy+M7LJr96LoTcgQb eNuhcHdh9Bu9IxAE33ON2NYY5rbWSG8KhQIQSs4/6RHgy4JgV4UROKg5zvhbbxxluPrq k1XlbByipp5V4x0CJccjkVtayRsWljKxMS7/5HO4eqf/LgQOlB0ZOrxxRBnTOpmec39w 6lrA== X-Gm-Message-State: AOAM5326skrZg+hXM7qIf8PvHxwNbl6IIbI3XTWDczELEwAoe4+iBUjl xTEpNbuA73ZFu6m36nIpYvvfAmIBdGs= X-Google-Smtp-Source: ABdhPJxykuXtOa5EHH++moTjMroPgkHu+jGNgnpmaWaK1wgPwgeuOaq8LfuccHS39b+C4rvZ89l5Og== X-Received: by 2002:aa7:db49:: with SMTP id n9mr5129529edt.361.1623922295955; Thu, 17 Jun 2021 02:31:35 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 01/45] vnc: avoid deprecation warnings for SASL on OS X Date: Thu, 17 Jun 2021 11:30:50 +0200 Message-Id: <20210617093134.900014-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x532.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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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" +/* + * 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) +bool vnc_sasl_server_init(Error **errp) +{ + int saslErr = sasl_server_init(NULL, "qemu"); + + if (saslErr != 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; }; +bool vnc_sasl_server_init(Error **errp); void vnc_sasl_client_cleanup(VncState *vs); 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); #ifdef CONFIG_VNC_SASL - if (sasl) { - int saslErr = sasl_server_init(NULL, "qemu"); - - if (saslErr != 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 = lock_key_sync; From patchwork Thu Jun 17 09:30:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54236C2B9F4 for ; Thu, 17 Jun 2021 09:33:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 051E1613F5 for ; Thu, 17 Jun 2021 09:33:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 051E1613F5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoPC-0005j1-31 for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:33:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNB-0002a1-0h; Thu, 17 Jun 2021 05:31:41 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:44736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoN8-00060W-Vg; Thu, 17 Jun 2021 05:31:40 -0400 Received: by mail-ed1-x52a.google.com with SMTP id u24so3017693edy.11; Thu, 17 Jun 2021 02:31:37 -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=Sp/voqCK4St+zItPkwDM9X8sXGTpdFyHS5ZFLpz1DD1rZQbtHo1+0MqzwPO/2JlYFj jBPUaRrXIGr1klCt3yYEdgD905fKOFABPTaUFminHXdvJfiR+3xvpQJwRIrYG5tVIuKC EyW0gcphH2epeYuigNw5c8fyyptrEl3S7IuZdJO4qsQULe+y2XhHGaSlrZg0DDBxswsi FiT/WSf+L1dxBZi+5tmh2giBdAaKlyt8g2p0rkOfNXAUfrpvq4NFxKflq3kAG4nxytsa VAKNy7pB2dkHrtC0q2vIbq6Il6d12gunb41Jy7lJoZaAQVyj2zVfx193zOWtW/BqWhCq WTDA== 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=ph+3jEECuY6/o3n2ORGEVYL62tal0knjo72Gmu5TDbDDj9Nza99tWzGYjxtwTBP5Yw GAtjWHHh8optSIrG+rclrYk6TE63JUeYph2ZpyvYGbv1N1oBpZz8nkTZSpgxTLq6U39b LtAmCSvWeb8xzbVMDH37TnNq/l5SLhz30sT0KQDNOAnVxlIcKD7W/J2FgZcuB/G51fnv M3dVRddUEKlDcvYRkxwYBAgDzUNdj9D8ErZbZ5eNlykLHUCmgy1vajMppus1eszzdvkH 8DplKJ/wWWuqdHhtpyzn1qkylxKWR0nIcasgvrduo/04lVg6gGO9frh+zU+TacIqcmRa YLwQ== X-Gm-Message-State: AOAM530vt8b9gZtpWL/gQ7RRyVfe3AH21+MCfVeXIMt6u73LVVah4s8G nL5o7lQGHL7ZETi44P4q9LwCgqkLQSY= X-Google-Smtp-Source: ABdhPJwhuEaCHDhjlb9MuZOn+u978Ean1I1gAx4fJnQEnJUXXdwdBpoVeanSymqgmrhJwn6CuSq18g== X-Received: by 2002:a05:6402:28a:: with SMTP id l10mr5178173edv.365.1623922296680; Thu, 17 Jun 2021 02:31:36 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:36 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/45] vl: Fix an assert failure in error path Date: Thu, 17 Jun 2021 11:30:51 +0200 Message-Id: <20210617093134.900014-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 == NULL' failed. After fix: qemu-system-x86_64: cannot create PID file: Cannot open pid file: Permission 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 separate 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) static void qemu_maybe_daemonize(const char *pid_file) { - Error *err; + Error *err = NULL; os_daemonize(); rcu_disable_atfork(); From patchwork Thu Jun 17 09:30:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D870C2B9F4 for ; Thu, 17 Jun 2021 09:35:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 460F4613E9 for ; Thu, 17 Jun 2021 09:35:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 460F4613E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoQy-0000ms-D1 for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:35:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNB-0002aN-86; Thu, 17 Jun 2021 05:31:41 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:46733) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoN9-00060r-C2; Thu, 17 Jun 2021 05:31:40 -0400 Received: by mail-ed1-x529.google.com with SMTP id s15so3014664edt.13; Thu, 17 Jun 2021 02:31:38 -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=XCXGOFoxS2/QR0BNcTPwxXWTIZpvsP7/DZqFhpzElKZoHhzGR7JiDuNxR9LDEaLi9K b72XTzjE/45bKk7VLr3Cfz+1c8au7uuieEvZI8xIItzyIi4AqktGjEKoak6/+S8aJ1Nn g8sl60lus9tDM7lo+DJxE9cso1aShUtnzr3pURtYgqUPt5PEX3NwOgZ/ibeUR3d8NI9w PcvEyhS8VzGe3rQWwMuE9UOcolcr6GWv43oX2Xh1zWjaOpqdCvpwrXmmKE+X2EhSu3Nd 637pfBG9d7GJiwVSTLh94B1z/QqVWSSg3excz79MjQvYXcPZ0Z+vxMIZfdwomkuTHPMh 2DsQ== 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=jyteUrb04QKiD89oCfjWBQ3qWd61DLbmvtInC/lAzAPeo3Jq5KvkYq5FiSzGDJGTT3 e+KVtWvROpeyd8RgUp1BOUubDgqsQrCidZql42kr7oV+pPx8eiYL7U29yK/NbOMyjav6 nR1spbrnmxE5OzGLDF9GSGCNF0mXDjzWTzvNkgttvcFRS7b9nE5s7sM5Ewfbma/nlrwk aCvoJE1hdadUPsGtX2LiC2+4chXkU5Nl45naiu98rZhAaLLSiIJ9Ei121gpLlyuxdLBi E3nibKzn+Alj0y485WjjSIDlMhbysV0wqC0Qr2vUckvqpKJLNUi5IX292XpizCpqKaMN by7Q== X-Gm-Message-State: AOAM532l6bOZBOMPh+oN4ExM8QnPg++UoUscg4GqGKDgUYnCHpnnY5wc bxmdz1s0Jhy/P8X5eZgIGWf7lS6Rc3w= X-Google-Smtp-Source: ABdhPJzzv56jtdvp1oncDR0Uik9MPnw/pGoS2nz7cxoU/LFsE3uHVeFASYLYFTEe9qBKH1LUuA1r2Q== X-Received: by 2002:aa7:d388:: with SMTP id x8mr5144496edq.338.1623922297338; Thu, 17 Jun 2021 02:31:37 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 03/45] qemu-config: use qemu_opts_from_qdict Date: Thu, 17 Jun 2021 11:30:52 +0200 Message-Id: <20210617093134.900014-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x529.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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 validate. 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, Error **errp) { QemuOptsList **lists = opaque; - const char *id = qdict_get_try_str(qdict, "id"); QemuOptsList *list; - QemuOpts *opts; - const QDictEntry *unrecognized; list = find_list(lists, group, errp); if (!list) { return; } - opts = qemu_opts_create(list, id, 1, errp); - if (!opts) { - return; - } - if (!qemu_opts_absorb_qdict(opts, qdict, errp)) { - qemu_opts_del(opts); - return; - } - unrecognized = qdict_first(qdict); - if (unrecognized) { - error_setg(errp, QERR_INVALID_PARAMETER, unrecognized->key); - qemu_opts_del(opts); - } + qemu_opts_from_qdict(list, qdict, errp); } int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname, Error **errp) From patchwork Thu Jun 17 09:30:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70401C49361 for ; Thu, 17 Jun 2021 09:41:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27A70611BE for ; Thu, 17 Jun 2021 09:41:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27A70611BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoWB-0004nK-Bu for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:40:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNB-0002b8-Gc for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:41 -0400 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]:45741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoN9-00061p-FO for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:41 -0400 Received: by mail-ej1-x631.google.com with SMTP id hv20so2770990ejc.12 for ; Thu, 17 Jun 2021 02:31:39 -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=hj63UgmF556qZq7IVFAaJpe3gmmfJk73lqsRkgMF47rCsgnw9z9XoJTzCRIvz27EXY 65umkz3orqyqcDz+DKt1dzWOuH7I9rh/0QlsVuEMecoDafFxP7CqnZ0utDCzaDXsAdMZ K5oHp//g12iFh9YouWQ0ncqRiD9sIrvFcJHWFqWIGWmUOZiD7276xMjhe2PcvgnWXcji y4Hd7cmm4M96zwaJvi2hAAj1qGl5GPyahfm7kLtb0N92tXg7Y02uu4pRTwb7anhxVHFS /w2E+NS8HLtdGaipRkZgo592drcPA8IgGpkiV4nhKkGHeREfRVVxaHG+LigEVSt9klSv YqHg== 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=S070mjaF/B2XLQbsAXbPhNCQ5Tvcxr4DhIuF9rV5ANCnH1l0yirVZJ/JqygwHg2Jjq oDX95iDD2LLwCqZOCIwaB8k94XbQoG3k4Y2ETGO7Cl6rVTqsw2mvSUSzrnG/UhctnRya MZcW7RT2jx6OSWM+P224u7wNPjOCafXwEZIm32Och5q29JmVG2Gfu9zqTaF46vgqA1p9 BZEY7o6faOWMtxANpgoNglMgWD0JYqeJvFeeB8j2HYFwO+mcotmYYkLhnAuhh+zF4zGd 3qFgZMDUWtw/aclIykpuv8awkzLoRFQJM2yYUjBeYOFQRGkoexIBmNkBTe48RlpXv8Ga vx0g== X-Gm-Message-State: AOAM530poQQaEmTcKuzkZc6EYXaJFahsx/7bWSeNJSvoTgofN3qpxTYW hGvYzpse1e15Zbj5NaMpot8z3Q6u2PI= X-Google-Smtp-Source: ABdhPJzp7l7Xv/YLUs2UaAa8kZjiNF1LeRLTRLSNB40ivk8DJIH3k4mWdH/CfWwGsaiWTcw6OZyaaA== X-Received: by 2002:a17:906:318b:: with SMTP id 11mr4137248ejy.395.1623922298039; Thu, 17 Jun 2021 02:31:38 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:37 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 04/45] block/scsi: correctly emulate the VPD block limits page Date: Thu, 17 Jun 2021 11:30:53 +0200 Message-Id: <20210617093134.900014-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Maxim Levitsky When the device doesn't support the VPD block limits page, we emulate it even 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 length of the data to be copied to the guest, thus the guest never sees the VPD block 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; } -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; @@ -213,8 +213,13 @@ static void scsi_handle_inquiry_reply(SCSIGenericReq *r, SCSIDevice *s) r->buf[page_idx] = 0xb0; } stw_be_p(r->buf + 2, lduw_be_p(r->buf + 2) + 1); + + if (len < r->buflen) { + len++; + } } } + return len; } 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] == INQUIRY) { - scsi_handle_inquiry_reply(r, s); + len = scsi_handle_inquiry_reply(r, s, len); } req_complete: From patchwork Thu Jun 17 09:30:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327153 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EF28C2B9F4 for ; Thu, 17 Jun 2021 09:42:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D9E32613DB for ; Thu, 17 Jun 2021 09:42:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9E32613DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoXo-00025p-Rn for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:42:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNC-0002dy-Ow; Thu, 17 Jun 2021 05:31:42 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:36827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNA-00062F-KP; Thu, 17 Jun 2021 05:31:42 -0400 Received: by mail-ej1-x630.google.com with SMTP id nd37so8768672ejc.3; Thu, 17 Jun 2021 02:31:39 -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=ojzGIj/GQau9eqlf5tRBHGG7yTtNRVewdjWdVPydm0y60V6CYXcjUwL+TFaDZjLf6t dUO1pT5cVTDL+KkUsMEVsROsVU4O7rbbM4SLkFHlTy/bttKf7ah/us9iyeufU2HOpsAz vrKJsLmw9IJ2VpLo+SL9qfkgnyH+bJCTom8BYJvKc8GThyHlBS8lbBUp+jQNj0KFJUyj ijW8Bjn00OgXpL/UlmgHVLcoWgZK4x8kqxG3126oTnorAqgkTzXZuPN+QdoMhrjgeREw WbUUvMQ7a5MrglcdBHK526W3DNHuT0nhN23XI3AohSGZXpwOG29+zO/xZUpC3jGztUgq AX2Q== 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=ZMjiTrWOFZge/6bBnL5XjzIAz/NBmQpVdQWrEdOq+XLz2lGz/AU4LtJlRcSltghW6X Ay0BAQaF3sJMtkq3aSt0c9a2A4uNyUEEWm01wx/i0+MaQTGbYlSS8iXU365CguULLLuK VMh8rFVZcSfHbeXZukqa2NKAehraiGOVIFC6nr+JXAOlaDy5mOYyYcGQX9Iq1jWXNMEy 5v2nutpvqfNK3wPM13LvNpf/ZDFJrAz8gqmJ5sDJPnk6yjWoh/l8iGH/MvS5+faoGcks 5xtcq8hXK1sQesumVxc1mTXLEEfpfoUuKSdMS5a6nJ/h9+viejvPKF3nkX+qFqWdmEgX ybnw== X-Gm-Message-State: AOAM532P36wUVs80aOuHdjgNVcmr3SkR1Qgy1M+OkThnxoclJGevG3iP hcaaUXUubcMgzNOn+JRbTKfFyzFQTKA= X-Google-Smtp-Source: ABdhPJwAkRxOMfJ3QW3jFscuW4qbiWE+Fvnog20y6oLsH5xessQxVXnvNCGnAw3KOzfDSC2GKfgS8g== X-Received: by 2002:a17:906:488f:: with SMTP id v15mr4167034ejq.428.1623922298809; Thu, 17 Jun 2021 02:31:38 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/45] runstate: Initialize Error * to NULL Date: Thu, 17 Jun 2021 11:30:54 +0200 Message-Id: <20210617093134.900014-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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_P_=2E_Berrang?= =?utf-8?q?=C3=A9?= , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é 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) void qemu_init_subsystems(void) { - Error *err; + Error *err = NULL; os_set_line_buffering(); From patchwork Thu Jun 17 09:30:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED7E4C2B9F4 for ; Thu, 17 Jun 2021 09:34:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8BD4E613E9 for ; Thu, 17 Jun 2021 09:34:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BD4E613E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoPn-000792-OD for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:34:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54928) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoND-0002ek-0M for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:43 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]:43666) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNA-000636-Tp for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:42 -0400 Received: by mail-ej1-x62e.google.com with SMTP id nb6so8664803ejc.10 for ; Thu, 17 Jun 2021 02:31:40 -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=V4EqL6KdnAMEqYs4oc2N4c0U15Gh3z4G1USFyrAiHguNrPe0PK4dk42RongvWyQ0CG i9n8FQI6Swk3MkmIIa+EA3QCyoLfY84tR9hOSz+Udw8TEbjaChQY9ZNAB6vlodvLEk5Y 2j28bKGX/VcDHx5UlwJuTPr7UWXAsFjLR5YMeKyLaW5iW6yOzsS2crEG8QZtRZiwrkc9 TFJod6Z3LDAqsC7jLf8UyRAkGuDAVL/h5Zip3SEqAow8d3U5efR3dhRS058zE98aS4+G ieKwdmO+E9baseY4sPTtlNjw00ut1x31gtT/A8XdxFiD7Xx5x4wG4GtukDSYqVZ0a77g o58w== 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=W0WdeuyyucguOr7Aab8VkHgJ9xv+Sk4S3cG5hSfXSIhknUWX58cXjAIkA7gJIsqV1E QE2qPFf8DVrsAb0fyyeO187padOtaleWPSq7JjwU/phAFTuSguxEWPgCNWwezsQkLE4+ +Yv2q232F8ZQlN4Y1ohcY1oj6+Ohb1+LMN7haSrc4Y4kTnig3wlqUsn4bYjZBRXk+Jqg 7VFA9xoAFXl39bPjVawiNcUgxFdNpmeprggmkVBjG/jdzpDsOQDdAtd4R/X+MWqkxgVn asqrjlp4H/J7/aqOpE7KlLrEh9Ck7qqu7mSfG1VTT5CZbcxsXNRHCa2UnpXL2/eA6VJ2 KHKg== X-Gm-Message-State: AOAM5322S33KmNnLllwF1z4dgBlMDSa9TYHBtmzQQ6/6taeUF/QcDhPr EVlUtWmbE0q0tYydLumVpn43ccxhPFY= X-Google-Smtp-Source: ABdhPJzjZPo+GKIZ5AoIO9bMuaZcI4aGjwv0arSm1BTcs9PjLzvLd0Jk+NTDEFtvtrSGIa4D5rsM8A== X-Received: by 2002:a17:906:27d3:: with SMTP id k19mr4116169ejc.368.1623922299482; Thu, 17 Jun 2021 02:31:39 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/45] esp: only assert INTR_DC interrupt flag if selection fails Date: Thu, 17 Jun 2021 11:30:55 +0200 Message-Id: <20210617093134.900014-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Mark Cave-Ayland The datasheet sequence tables confirm that when a target selection fails, only 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] = 0; - s->rregs[ESP_RINTR] |= INTR_DC; + s->rregs[ESP_RINTR] = INTR_DC; s->rregs[ESP_RSEQ] = SEQ_0; esp_raise_irq(s); return -1; From patchwork Thu Jun 17 09:30:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E688C2B9F4 for ; Thu, 17 Jun 2021 09:37:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F5126117A for ; Thu, 17 Jun 2021 09:37:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F5126117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoSm-0005Ed-ET for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:37:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoND-0002g0-Br for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:44 -0400 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]:41658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNB-00063X-KI for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:43 -0400 Received: by mail-ej1-x62e.google.com with SMTP id ho18so8719984ejc.8 for ; Thu, 17 Jun 2021 02:31:41 -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=iRxUQ5U1f9NzMLxIfLn8j4AwpPzk3U0oTHl1DniHkbf+eEWE+KeIP2CL1gdcZVtD/U zwYZtDHRE7NtTNjTx9/45K5zXPIAAEPxY17CAUuA/aYwDRF1iA8EWozH+ZmvBDkJjqW0 yOvoepgz6JCDWy5TFGpqGx0QgPYNOlCEA34NZaN7oZ7yqWkTlCD/3QGRShTbPpvlQiWd awjqi9Sz6cFsiOOed3OFOmMlWm5sXmW3fOtqO8TdJhOFPhMQL7dYdwyoVMjk6Gx8vJKd UXg6duk8Ak9Bn7BDSFXQr4vPwRQ+uYYQ7G3qS4Xo0Jn6p81ZnehmI97ik/ViSJuLBt4L HF1Q== 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=Ub+XjU0lS2K2Cn1f/1qt7UK5O4HHZDoZk14BtrC4a34Be+51YZ0mBTJsFzFub/YHvn klcm1V8K+3AYlV4sC/lW+I+lj7/m/okQ32OsE9xXU1koBFrWfHnrtBLRPTsuI8Fp7STB UavgSLJQflX4dwMq5PnnB47y3ugxlvVY/rD09yaEwNO8uNfWiQoOto/W73s/V5Nd9QEn YTUDJnWeOZPIlDKN/b6uEwJJ6HCD401Lh4etM6tW/3Lmx+A5/QKq8SttS6WhdmIpgNEn +qwU0uVAniWyjbbDuFnJ9Nj2PWI+5n1DGP/9YQeJ9xSKPSOlEiDrLE8+SDcuEmS815uT tzUQ== X-Gm-Message-State: AOAM530SPtNtsb6ch0q8rHYKI1cbYtZ77y9oSbwgaAO5k8+BYUJe431V djQMMqi2hMIWJ596Us6Od1eMYJn/ECc= X-Google-Smtp-Source: ABdhPJziQgDifU19btvAhZmE010mxD4axOyVJlnkk8+q1iP5YCsOwDcddka14xIIKxIglzDr8DXjnw== X-Received: by 2002:a17:906:110b:: with SMTP id h11mr2101942eja.356.1623922300182; Thu, 17 Jun 2021 02:31:40 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/45] esp: only set ESP_RSEQ at the start of the select sequence Date: Thu, 17 Jun 2021 11:30:56 +0200 Message-Id: <20210617093134.900014-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 step 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 flags. This reason this mismatch occurs is because the ESP emulation currently doesn't update the bus phase until the next TI (Transfer Information) command and so the cleared sequence step register is considered invalid for the stale bus phase. Normally this isn't an issue as the host only checks the sequence step register 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 interrupt register and clearing the DMA status, so the guest sees a valid sequence step 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 the 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] |= STAT_TC; s->rregs[ESP_RINTR] |= INTR_BS; - s->rregs[ESP_RSEQ] = 0; s->rregs[ESP_RFLAGS] = 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 = s->rregs[ESP_RINTR]; s->rregs[ESP_RINTR] = 0; s->rregs[ESP_RSTAT] &= ~STAT_TC; - s->rregs[ESP_RSEQ] = SEQ_0; + /* + * According to the datasheet ESP_RSEQ should be cleared, but as the + * 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 phase + * transition. + * + * s->rregs[ESP_RSEQ] = SEQ_0; + */ esp_lower_irq(s); break; case ESP_TCHI: From patchwork Thu Jun 17 09:30:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8B9AC2B9F4 for ; Thu, 17 Jun 2021 09:36:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8BB156113C for ; Thu, 17 Jun 2021 09:36:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BB156113C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoRt-000391-NQ for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:36:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoND-0002g6-Sg for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:44 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:35635) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNC-000645-8j for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:43 -0400 Received: by mail-ej1-x634.google.com with SMTP id gb32so550044ejc.2 for ; Thu, 17 Jun 2021 02:31:41 -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=mfrHPX/zQ1fB8sTEhv3f5bKq0jV1M4temQXv6WSi7Zdr5fe6pJAVoB5di/lwYBS4Nf sBfqFNejRTs3npUxTPlpnFL6gOHFP4Be5f5be7JrHBtXPvZjR+K5kwD04d2y7p79KFxA /9Zosr3/YZicm5npk78P5tedqEqU0IvBs8VD0AquvaLYx+KjRSDciwZGkzBK02cNyQPL IiERUCkmpd0PNjiNnyAnbDXGkccsR0bjJZ6virvdjbux+D8UlqzGcl8teNiN0RJb+c6a peee4FoLXTVAo5M69fpDbSARMGRYI/CN4/FNDL6hvxBWIzGK9k0Ig9EcUoYhz2ma1SDk EXWg== 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=CxYXoYkFTrpjuy8BNXQavX6QCbUX+qML4AaRPoRI9ddRLcAiIJJ/H8fM5c3LKCXfxd bBwBXrxvaq5vJ39akM3K2U9tlOrfIXtiTWIA3bNzLxwWU8jOMl48VbHTa4e5ul6m5Z4c ymVhC1wJhRk59LTYy6gifXPUNEfEyxhB6QGUJpaapEGRUUL8SUGs+86v95XK+1OAyZk/ lkNJqSoojUVP2ZF9Yv0XPs1w++HdDkOmGRB+0eC+hMxq0q5woS4rsGpxZTx3cPX3S5NP 4/OHgcNh+mAHQs9ccjM7/yTyYGEuhvVcLpXGO6Z+3kD25vfJvDpcstCpGEOiQ97E9FTf jCKA== X-Gm-Message-State: AOAM530+l2rcJZpNvnw9bN8ca9XceI9+8bxHGXnKTS9/3pLD0cU84WZ/ pXwzS3ETifpGQggoVQrCZ4uytnwJAYo= X-Google-Smtp-Source: ABdhPJzvaKV494t5IgoTlxyFui5va+vY1r+yiOIkDyurobHForR0K8fJ5eHunRbACVBhQeusPiUUGg== X-Received: by 2002:a17:907:1c13:: with SMTP id nc19mr4330808ejc.168.1623922300844; Thu, 17 Jun 2021 02:31:40 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/45] esp: allow non-DMA callback in esp_transfer_data() initial transfer Date: Thu, 17 Jun 2021 11:30:57 +0200 Message-Id: <20210617093134.900014-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 transfers 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] |= STAT_TC; s->rregs[ESP_RINTR] |= 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] == (CMD_TI | CMD_DMA))) { - esp_do_dma(s); - } - return; } if (s->ti_cmd == 0) { @@ -826,7 +816,7 @@ void esp_transfer_data(SCSIRequest *req, uint32_t len) return; } - if (s->ti_cmd & CMD_DMA) { + if (s->ti_cmd == (CMD_TI | CMD_DMA)) { if (dmalen) { esp_do_dma(s); } else if (s->ti_size <= 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 == CMD_TI) { esp_do_nodma(s); } } From patchwork Thu Jun 17 09:30:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19724C2B9F4 for ; Thu, 17 Jun 2021 09:44:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A96E3613EA for ; Thu, 17 Jun 2021 09:44:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A96E3613EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:51218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoa0-0007mm-Nt for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:44:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNE-0002gx-WC for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:46 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:41664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNC-00064r-Qa for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:44 -0400 Received: by mail-ej1-x634.google.com with SMTP id ho18so8720092ejc.8 for ; Thu, 17 Jun 2021 02:31:42 -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=uPGZouCc1370kKoTE7lCT4N/fWC5VVMfNgl3VKSiu6sO9bWm01uVphDjGVzeY/Sj9f onW1Fbg8ZfSeF85GcxItnl2UUZl2dBH4+m5MXZnoSIbZUGE0W4S3cFh7BLPb+YqI7xs2 IYt3alX7xXJuooUZMHvKdE78RdLR2LanhpLYUu4CwCNcgTFk+pEC0n5wsXEbFEm/3EMF YSctoAv4UO4Kaz6k9A6QmTNlmmNcNGmXhQGgbtne5WuBMVytHh5r9ykCrqczV2Kw8qgU BYgpRZ22O6lXrPftQsJt0Aq36YuOPuVGidpDbZUOEASS2b0KMiPXpIEAoaO2c8t0hziX SvZw== 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=WQjEqJuGESX5XnVAENh9CkMKGoYGt3/JIP43QHxjA6gLYaO6KJsoB+L2pNOAoTsObC L0O5CTJL9aWzCLc7Nj0CH61GkSvnVl1liuq9KTRYh+WTiBL+5gUr8XfaEv2k7ca9lURL kqR/0YkfpI312UojAb3y6vAMJNzt8K34gnR712btDt1GOlw7YdVal9ow4FbXk8agpeH0 gwO4WrkD8kybHilSBe7tM2Ti/KrsAat8rsrVX7yvVpmu7lBx7QkEq6K9RVtO0gMUu99j fyTECF01gr6JhSd0LGwEht01hNKAcQOoDF33gNqmbumklbaJRMvdXDKaw3/JAYzOR+Nq zJKQ== X-Gm-Message-State: AOAM531QOeOUyqxPDCKEGoJDtSIc0s72z9yiTXvDKKbanThFKXy6zDty qmfZ+loQebGpGqZnRP4AVVl8+dEsAB0= X-Google-Smtp-Source: ABdhPJzLFTEuhQgEg+s5piM8r/6XyM7qGYdehbzJG8SPSgyMINrEJZEoSZp/MY24NE+gVw108PJ/VQ== X-Received: by 2002:a17:907:2636:: with SMTP id aq22mr4305925ejc.48.1623922301466; Thu, 17 Jun 2021 02:31:41 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 09/45] esp: handle non-DMA transfers from the target one byte at a time Date: Thu, 17 Jun 2021 11:30:58 +0200 Message-Id: <20210617093134.900014-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 interrupt should be raised for every single byte received from the bus and not just at 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 every 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 -= len; s->ti_size += len; } else { - len = MIN(s->ti_size, s->async_len); - len = MIN(len, fifo8_num_free(&s->fifo)); - fifo8_push_all(&s->fifo, s->async_buf, len); - s->async_buf += len; - s->async_len -= len; - s->ti_size -= len; + if (fifo8_is_empty(&s->fifo)) { + fifo8_push(&s->fifo, s->async_buf[0]); + s->async_buf++; + s->async_len--; + s->ti_size--; + } } if (s->async_len == 0) { scsi_req_continue(s->current_req); - - if (to_device || s->ti_size == 0) { - return; - } + return; } s->rregs[ESP_RINTR] |= INTR_BS; @@ -762,20 +759,37 @@ static void esp_do_nodma(ESPState *s) void esp_command_complete(SCSIRequest *req, size_t resid) { ESPState *s = req->hba_private; + int to_device = ((s->rregs[ESP_RSTAT] & 7) == STAT_DO); trace_esp_command_complete(); - if (s->ti_size != 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 != 0) { + trace_esp_command_complete_unexpected(); + } + s->ti_size = 0; } - s->ti_size = 0; + s->async_len = 0; if (req->status) { trace_esp_command_complete_fail(); } s->status = req->status; - s->rregs[ESP_RSTAT] = 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 == 0) { + s->rregs[ESP_RSTAT] = 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 = 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] = 0; } else { + if ((s->rregs[ESP_RSTAT] & 0x7) == STAT_DI) { + if (s->ti_size) { + esp_do_nodma(s); + } else { + /* + * The last byte of a non-DMA transfer has been read out + * of the FIFO so switch to status phase + */ + s->rregs[ESP_RSTAT] = STAT_TC | STAT_ST; + } + } s->rregs[ESP_FIFO] = esp_fifo_pop(&s->fifo); } val = s->rregs[ESP_FIFO]; @@ -952,15 +977,18 @@ void esp_reg_write(ESPState *s, uint32_t saddr, uint64_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] == CMD_TI) { + s->rregs[ESP_RINTR] |= 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] == CMD_TI) { - s->rregs[ESP_RINTR] |= INTR_FC | INTR_BS; - esp_raise_irq(s); - } break; case ESP_CMD: s->rregs[saddr] = val; From patchwork Thu Jun 17 09:30:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED674C2B9F4 for ; Thu, 17 Jun 2021 09:38:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A7F306113C for ; Thu, 17 Jun 2021 09:38:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7F306113C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoTp-0000Jo-St for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:38:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNF-0002hD-3g for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:46 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]:42768) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoND-00065M-H3 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:44 -0400 Received: by mail-ej1-x62f.google.com with SMTP id di5so2498042ejc.9 for ; Thu, 17 Jun 2021 02:31:43 -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=V3FS0kO0PUCa3afO+1c26gtBDff5rM19odHbkkSQrlrJ82rr3qiJalJhBmfKP2IYLG vsDO1Aaf3TmXXWIqtz2AvGmSvuGbBFyzHk9x8XZ6TvkeKhnKZZUxxtqLWyMx2frpPkVm 9TY8eJCjPgj8d1UBzhhOYuTKRLSCUyl1YowT4+bFYkUZBFA3JbC07O5zqXT/L4aDtr5a hEnLhgLiFw1cui3XuUdZ/Fik8rGE6HV1QWaemZSZ20cXfu60YZct/eIXa7Q37r3CeWPb tuwUNbHXn6ETAjxmr5hjM0n+YGFs1w2nB/LDh/lO6aqnGJStlAeoAjUC6LwELQ7UUWAQ qmqQ== 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=F1CpOdkCRG+0vDHkB4dqhbvOlUcgVHsmk37ypbPO0SGXNlbb4X6UDTShjfsgVQY9Ry +bIupZRejZzYbJ6aXzU7v2RmwZXQQW5+muLHbwh7BWFs4ruAL5EObHrmQEh9b5UGE3f1 yhEvUeoZdsY0xRaFkFPVqcOJdiboz05IlcsgihkmRkFoP4dmONoL17MF1WUDMBZyBgWG OircIwhS3hEAXc+CA/HZky2anWA+jaK/he2ZKXEdQVjgGh6IrK69S/F1yR/KQSAwdnXP ZYVDNG1S69m0NYLvyWqv2hUxO6vCC7iVtHTemW9cQ0qQw+tqFZmcNSk2NeE5bNLpMIxS 1Vkw== X-Gm-Message-State: AOAM532lf+BpGX+LwWkGpXmKbXFsXIwetQ3YryrpDPfZ8SOAtYnd7MWt BaAYEmbjapwL5dk6gRu6OcntxUIpnCY= X-Google-Smtp-Source: ABdhPJzOoXZMzhEvfZNVxI1dqEgB0uWM82s+DSy1CV+0IcaE+0INqCO8Zl+PCg6buehcnJDjYqqiVQ== X-Received: by 2002:a17:907:9047:: with SMTP id az7mr4257080ejc.4.1623922302164; Thu, 17 Jun 2021 02:31:42 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 10/45] esp: ensure PDMA write transfers are flushed from the FIFO to the target immediately Date: Thu, 17 Jun 2021 11:30:59 +0200 Message-Id: <20210617093134.900014-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 FIFO 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 after 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) static void satn_pdma_cb(ESPState *s) { - s->do_cmd = 0; - if (!fifo8_is_empty(&s->cmdfifo)) { + if (!esp_get_tc(s) && !fifo8_is_empty(&s->cmdfifo)) { s->cmdfifo_cdb_offset = 1; + s->do_cmd = 0; do_cmd(s); } } @@ -369,12 +369,9 @@ static void handle_satn(ESPState *s) static void s_without_satn_pdma_cb(ESPState *s) { - uint32_t len; - - s->do_cmd = 0; - len = fifo8_num_used(&s->cmdfifo); - if (len) { + if (!esp_get_tc(s) && !fifo8_is_empty(&s->cmdfifo)) { s->cmdfifo_cdb_offset = 0; + s->do_cmd = 0; do_busid_cmd(s, 0); } } @@ -403,8 +400,7 @@ static void handle_s_without_atn(ESPState *s) static void satn_stop_pdma_cb(ESPState *s) { - s->do_cmd = 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 = 1; s->cmdfifo_cdb_offset = 1; @@ -493,6 +489,11 @@ static void do_dma_pdma_cb(ESPState *s) uint32_t n; 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 = 0; s->do_cmd = 0; do_cmd(s); @@ -1220,7 +1221,6 @@ static void sysbus_esp_pdma_write(void *opaque, hwaddr addr, { SysBusESPState *sysbus = opaque; ESPState *s = ESP(&sysbus->esp); - uint32_t dmalen; trace_esp_pdma_write(size); @@ -1233,10 +1233,7 @@ static void sysbus_esp_pdma_write(void *opaque, hwaddr addr, esp_pdma_write(s, val); break; } - dmalen = esp_get_tc(s); - if (dmalen == 0 || fifo8_num_free(&s->fifo) < 2) { - s->pdma_cb(s); - } + s->pdma_cb(s); } static uint64_t sysbus_esp_pdma_read(void *opaque, hwaddr addr, From patchwork Thu Jun 17 09:31:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5533FC2B9F4 for ; Thu, 17 Jun 2021 09:41:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21DD7613E9 for ; Thu, 17 Jun 2021 09:41:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21DD7613E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoWc-0005vX-AP for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:41:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNG-0002hw-RL for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:48 -0400 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:36802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNE-00066C-Nu for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:46 -0400 Received: by mail-ed1-x536.google.com with SMTP id w21so3070033edv.3 for ; Thu, 17 Jun 2021 02:31:43 -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=d61nTB0fIt1eXIJ73/+FsvAHFY4QHvtuSZISCJS0UQLf6DDg+u1hKUptLvKVKj1wzc Kbvm8b8bglpTsEvOT98UuFLvuosjLMRmdMxPuIwxZ4ElcRceEp3SY4PEUJP72kcLS9qD vKQtFEVsWj7LlTKAULMKjHZj8aukRTjgS1ycPivHA3hhnDtalkWGynbGRlfmq9adjNO3 lefmKygHUOpd8MA9rBj+qBFyrZfAlUFVDmpHZPf77578seAtJN32o00pg5sKezboxVJM UNP+nmiads84yktjtMj39FIgYoYfXSTeJahgk9+UbtgIwdb1NsTW+6f8F5ixN9bFAvZe Kfeg== 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=iUHmnQXE1/PVQOhYYQVlaz1pI7Eoa2+6wD9Lde6dgiI+oib9r5JFX4T4qcdGBL4njs Fqqyq+v94P1zt2MHK+mMyoH33C5iRZVz5S0TlNqn+LEBBvWnfU5T6P7ObUnzS0iPa9Si tY9GkdhFA6mOyQfTpFNewBCW0q41p2Y9QzW7kAQBg99XdoYeQL8NkvAyYod9Wj8quJg/ VC3LP1lf52AfLNLE34OFlTavOA4tcuWKT4zXVGBNmT/bmyiCdci2LCt1e2AiaFkIPHEs s6l2e7J/0qMZGqZGZOltWg6g2vLLimr433tLv+dMqajYZKJYeKZoSQkZr3KdHwSTnNRf KOQw== X-Gm-Message-State: AOAM530LH0sEyXMlVy8xk+TyT7UkSJ5Pgs2DZZKA9rF5orv7sQRC2r+i N1SsoEIVh1PJ7sL1VKAiRS+Zqpvxzks= X-Google-Smtp-Source: ABdhPJz+9o2KyZYgxVgzriY/gR2KS1iYhoZhDPSBlG/ygsFN5Gl+rr1cXszEDm9hcNg57fFKXgk5WA== X-Received: by 2002:a05:6402:2742:: with SMTP id z2mr5280719edd.66.1623922302830; Thu, 17 Jun 2021 02:31:42 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 11/45] esp: revert 75ef849696 "esp: correctly fill bus id with requested lun" Date: Thu, 17 Jun 2021 11:31:00 +0200 Message-Id: <20210617093134.900014-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 = esp_fifo_pop_buf(&s->fifo, buf, dmalen); - if (n >= 3) { - buf[0] = buf[2] >> 5; - } n = MIN(fifo8_num_free(&s->cmdfifo), n); fifo8_push_all(&s->cmdfifo, buf, n); } From patchwork Thu Jun 17 09:31:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B538C49361 for ; Thu, 17 Jun 2021 09:47:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18C9C613CE for ; Thu, 17 Jun 2021 09:47:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18C9C613CE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltocj-00059F-5Y for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:47:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNG-0002ht-R2 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:48 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:47099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNF-000670-45 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:46 -0400 Received: by mail-ej1-x62b.google.com with SMTP id he7so8671634ejc.13 for ; Thu, 17 Jun 2021 02:31:44 -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=Zoa7jA1KdNCb1zUJa/80mn3CKqruADOjhlyey3gqQpHtHcthslvVnPa8YyUT+T+d3v aGP19CfMEnZws/yJU0OffGaJZ9dGqX8xYDv7Z2uSow5/DiKOuxQkQNerqRYkTV5YAtr1 aW23sk3YYIQpvfSJeWTNR3gTjhj6ntKXH7cvhHPfCt2YXtlurGst4JYDq9xyWvz0ne6N 3wh/pfdSdFnbjGL0Mo8dTKbrON2yYmC313wbacxjyiYNM8WRnWEzrXxef8Nbywa7NLed GwVZlTVnsfy1QlWcppK2qZMajuLndsWCOKn1ej8WnqNKKHXCAMajrxHSCZEq1iGQcMHK j4OQ== 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=cboW6mABRo7TkngciSNgchFBpGyHD5KGQ27DG3FjdbXFAcxR25zJ51GOAnsUXUJHLD /h6U9wQxrjMcJ9w6x0fVe/BaEIP4ZAs6hCSc9OFASlMw47jt5pQW45VkvPq845svVWxm nozzfCy1Kq6I1cN+wfzBkLRNnBVptrAJkTvAiBl1wveKeoa5UL9/5RqEYY0w/mV3KBp/ iV1LmgT3q4z8SnjR9JaNkgK/dbH/woGku0vGdrbAuWTnYGA/GzjfW01oSCfQAYyIE404 9Lr6Bu+QPJmRocABg5qVMkzpUqBFjmpwxEN56cdcppivpeuWWsWd4duM/WKvhBPlLWXX zqsw== X-Gm-Message-State: AOAM5334CVTev/ekMKAz1AiHuugAgZDGyvSDB0CLqQYpB5NC11qFnhrv rSh4rG3lAgPkKytLuJHGbOAV/dp3iLo= X-Google-Smtp-Source: ABdhPJxAHxi9la+9Tde5JSW7mSYcZpI0fRPur1744qrewtPvoGxxxq8ijNBpQfe5yofenidY3TAfTg== X-Received: by 2002:a17:906:390f:: with SMTP id f15mr4314365eje.270.1623922303788; Thu, 17 Jun 2021 02:31:43 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 12/45] esp: correctly accumulate extended messages for PDMA Date: Thu, 17 Jun 2021 11:31:01 +0200 Message-Id: <20210617093134.900014-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 allows 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) } s->ti_size = 0; - s->do_cmd = 0; - do_cmd(s); - esp_lower_drq(s); + if ((s->rregs[ESP_RSTAT] & 7) == STAT_CD) { + /* No command received */ + if (s->cmdfifo_cdb_offset == fifo8_num_used(&s->cmdfifo)) { + return; + } + + /* Command has been received */ + s->do_cmd = 0; + do_cmd(s); + } else { + /* + * Extra message out bytes received: update cmdfifo_cdb_offset + * and then switch to commmand phase + */ + s->cmdfifo_cdb_offset = fifo8_num_used(&s->cmdfifo); + s->rregs[ESP_RSTAT] = STAT_TC | STAT_CD; + s->rregs[ESP_RSEQ] = SEQ_CD; + s->rregs[ESP_RINTR] |= INTR_BS; + esp_raise_irq(s); + } return; } From patchwork Thu Jun 17 09:31:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F553C2B9F4 for ; Thu, 17 Jun 2021 09:37:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1779F6117A for ; Thu, 17 Jun 2021 09:37:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1779F6117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoT8-0006cl-7f for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:37:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNH-0002ir-Lp for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:48 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:45739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNF-000673-Su for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:47 -0400 Received: by mail-ej1-x62d.google.com with SMTP id hv20so2771531ejc.12 for ; Thu, 17 Jun 2021 02:31:45 -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=TNvsFmWjs9hjhtdz/NTLh0EI3exvLmAcIIkw80pNCbZ78y9/hIYjmjQ+eLCPQSPa0/ NzUAxMrV6mIGlrDl1UI4A0glTkDeYI+fmgQxbgRLudMLKu0n1gmXcPnd9Tz4J/z7LXhi uriPNtBd//YopURF6XXudnjpRVbM9PCkK6s6gLLAj/eP1pBpaMVb0bm8loB2Zmaj0yBo U0iTjaevevsh87VqzWREnr2A0akl1JERblZo/xHYqC0RuAjoL9Db74IhwZgpCJfjsGaD rQPQIDh+yM/NJA74YTDZhfyC4VUPT6OTV+f6zdshA7W7KuTkRT/EimOfM3DzQVeH0xs4 mfZQ== 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=Oj/yO7e+PLOaf4JrWSl90kku8nc2JWbm3TiiKdXRUPKBL0FyfPGsjGcRte9fFu6Z/e VDawKkEiavt9sjRAM3pEm/GpEFRTdTrFRP++ybKtTjobjt2qcNul9VtUiqTBtatYTy8/ arBlgwAOAG1oDni8r8JB/Rn7tfXHq5d0w3qtqxKzXwSyoEFG//dRiKCzdt129p2z2ToS JL+q9Gc25lxOebClGp5ctM0scc3iMmIy34IArzfOcg8KqR1Pin/FllI03jxFV1OzvBZk 9ZaSxQbqKgdUv2SdGdIcDQv2ILK5I1oziOJ7Ap+UGICVDas4G4F+yLxmo1M21lddGyqA hWjQ== X-Gm-Message-State: AOAM530bttM93ftx9wHmmdaLd45bJdTuP797Jdf+20wiv9+yzKPHa/pq GKjq9zew/X1G5kBV8KvHl2QXuXaNwWc= X-Google-Smtp-Source: ABdhPJzqIc/ZXEo/kZxdVlcTKJ6jGYG9JokWsAbhNSlLY6dtY19GJFnulOHMCf/WltSNcpYFg5QPoQ== X-Received: by 2002:a17:906:4e96:: with SMTP id v22mr4165085eju.23.1623922304468; Thu, 17 Jun 2021 02:31:44 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 13/45] esp: fix migration version check in esp_is_version_5() Date: Thu, 17 Jun 2021 11:31:02 +0200 Message-Id: <20210617093134.900014-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 the outgoing migration stream. Change the version check to use >= rather == 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 data 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 version_id) ESPState *s = ESP(opaque); version_id = MIN(version_id, s->mig_version_id); - return version_id == 5; + return version_id >= 5; } int esp_pre_save(void *opaque) From patchwork Thu Jun 17 09:31:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1548EC49361 for ; Thu, 17 Jun 2021 09:40:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A75446117A for ; Thu, 17 Jun 2021 09:40:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A75446117A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoVv-00047w-Qu for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:40:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNI-0002jf-Tu for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:48 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:41763) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNG-00067q-Ji for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:48 -0400 Received: by mail-ed1-x52c.google.com with SMTP id n20so3046278edv.8 for ; Thu, 17 Jun 2021 02:31:46 -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=B1BE/Obe86+8WLSHaLO9HoNYABuN5CJbj9KdHIw033+JJZnSBZ9qnAglDYNeutfzM3 H4RRwzGpCbVZMbKXv/L91HveDfAO+lhC146DBiLylUVag9PXAxlCIDEb7bSN2XAHt5QR OwJzzgAXqj+HMbQKCYgV9k44Kuec2mYj8bgtKkHZpzcWsPEYrvkLZEsTzQThx/Z6MQYx li31wUQHs5IAmTdX3GVMsirHmLy4HqG0Ar1fm+V2eFpn5oKlXsiQ5bMk502241xhJc1+ 1aN3aaQ2QN8Q1Cr/7RjcZctaLRyooyvnyqW5CfbpuUWOApPPJabPHcBQTBSdNpJtN0f6 +MZg== 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=SNNG6RxpGXJzzKO6roXfXSvsEThnSObS4TlJqg2hrspChTxraC6G2mtJ5mrcwUeU8E 6gokEu7i9UZXwH8THyVlICNj23+xoiR18zfVg2QR08QWFpObQ1tKKpdiagXUPQvpq07s 3VaEfvDl8WnZnetxaTJ5M3Uwc8QCeTkIQmzBl0BN9aTyVpoxYE/+RMA/oIe0gwzru7ow AUm2HIk8ap81CmDMgpCDu6eDA7Lu0wIRe3esk6XifsDcQskA/vvRtIT0B7VkgjV0f5pI WAhkKAVCjiMi68fqSTA/FsItgGtDdNmHRCRCwB4xSzaTA9JhwkfzljpiEjX0+/xhUF2J N3ZA== X-Gm-Message-State: AOAM531yZvaF2oc15HrbAS8nuXW5pgidSt3R62JsaPheBcXCFbW4hcuH UkdUrtJYZMoT9QenARfReVOv68FbZH0= X-Google-Smtp-Source: ABdhPJwAzebAjNz9GYOnSBBVOPKWVTLhwBfNIFwzK0DQZ7J4Qs9JerrOJtQJK1eCG6/hE6asE4n1Ww== X-Received: by 2002:a05:6402:1d06:: with SMTP id dg6mr5100975edb.132.1623922305149; Thu, 17 Jun 2021 02:31:45 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:44 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 14/45] esp: store lun coming from the MESSAGE OUT phase Date: Thu, 17 Jun 2021 11:31:03 +0200 Message-Id: <20210617093134.900014-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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) /* * Note that we deliberately don't raise the IRQ here: this will be done - * 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 deferred * IRQ mechanism in esp_transfer_data() for DATA IN transfers */ s->rregs[ESP_RINTR] |= INTR_FC; @@ -272,24 +272,22 @@ static uint32_t get_cmd(ESPState *s, uint32_t maxlen) return dmalen; } -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]; - trace_esp_do_busid_cmd(busid); - lun = busid & 7; + trace_esp_do_command_phase(s->lun); cmdlen = fifo8_num_used(&s->cmdfifo); if (!cmdlen || !s->current_dev) { return; } esp_fifo_pop_buf(&s->cmdfifo, buf, cmdlen); - current_lun = scsi_device_find(&s->bus, 0, s->current_dev->id, lun); - s->current_req = scsi_req_new(current_lun, 0, lun, buf, s); + current_lun = scsi_device_find(&s->bus, 0, s->current_dev->id, s->lun); + s->current_req = scsi_req_new(current_lun, 0, s->lun, buf, s); datalen = scsi_req_enqueue(s->current_req); s->ti_size = datalen; fifo8_reset(&s->cmdfifo); @@ -316,21 +314,29 @@ static void do_busid_cmd(ESPState *s, uint8_t busid) } } -static void do_cmd(ESPState *s) +static void do_message_phase(ESPState *s) { - uint8_t busid = esp_fifo_pop(&s->cmdfifo); - int len; + if (s->cmdfifo_cdb_offset) { + uint8_t message = esp_fifo_pop(&s->cmdfifo); - s->cmdfifo_cdb_offset--; + trace_esp_do_identify(message); + s->lun = message & 7; + s->cmdfifo_cdb_offset--; + } /* Ignore extended messages for now */ if (s->cmdfifo_cdb_offset) { - len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo)); + int len = MIN(s->cmdfifo_cdb_offset, fifo8_num_used(&s->cmdfifo)); esp_fifo_pop_buf(&s->cmdfifo, NULL, len); s->cmdfifo_cdb_offset = 0; } +} - do_busid_cmd(s, busid); +static void do_cmd(ESPState *s) +{ + do_message_phase(s); + assert(s->cmdfifo_cdb_offset == 0); + do_command_phase(s); } 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 = 0; s->do_cmd = 0; - do_busid_cmd(s, 0); + do_cmd(s); } } @@ -386,7 +392,7 @@ static void handle_s_without_atn(ESPState *s) if (cmdlen > 0) { s->cmdfifo_cdb_offset = 0; s->do_cmd = 0; - do_busid_cmd(s, 0); + do_cmd(s); } else if (cmdlen == 0) { s->do_cmd = 1; /* Target present, but no cmd yet - switch to command phase */ @@ -1131,6 +1137,14 @@ static bool esp_is_version_5(void *opaque, int version_id) return version_id >= 5; } +static bool esp_is_version_6(void *opaque, int version_id) +{ + ESPState *s = ESP(opaque); + + version_id = MIN(version_id, s->mig_version_id); + return version_id >= 6; +} + int esp_pre_save(void *opaque) { ESPState *s = ESP(object_resolve_path_component( @@ -1168,7 +1182,7 @@ static int esp_post_load(void *opaque, int version_id) const VMStateDescription vmstate_esp = { .name = "esp", - .version_id = 5, + .version_id = 6, .minimum_version_id = 3, .post_load = esp_post_load, .fields = (VMStateField[]) { @@ -1197,6 +1211,7 @@ const VMStateDescription vmstate_esp = { 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=%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; bool data_in_ready; From patchwork Thu Jun 17 09:31:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F77DC2B9F4 for ; Thu, 17 Jun 2021 09:43:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4D0F9613DB for ; Thu, 17 Jun 2021 09:43:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D0F9613DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoYT-000377-EX for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:43:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNI-0002jj-Vc for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:48 -0400 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]:44929) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNH-000681-4R for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:48 -0400 Received: by mail-ej1-x62d.google.com with SMTP id gt18so8688321ejc.11 for ; Thu, 17 Jun 2021 02:31:46 -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=n7nffUNP3ajfEokW8OxvbBSdFmM6TZVEbVEjMCosEdIczjzRuPhqnULgFXzrAqelM7 IV1xCNjWLvHL7Zfh9TXvYGTfImCo2xYfmgrmkLebaIr2h9DfNz05ssfIKuzifuluFv0+ pDQ9ozGRp/KwzNMmZ0bSu1nfqZ/OvBWfM+GuBLJY6XNg8rjHaMV3MI/tWOlkJSj3/JIv YfPGBvc5FPiobtVqL/WDCQB1MPem/MomRaAumnC3KGrtY8mSkcn350AUlr4auaNbnKFt 9C7WRVRJRYpvoNjaCn4Bybl1xunl6aNd0s9hMXf0iaKxim7IgQ41TAcgD0GyZycjsx9Y VHVw== 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=L8VgSEwk7hUTsFcYZ4tsqnE8f1rpZCRWzN8zCFYW++yhjEO7cuwomN0F2a9BmRJiKt Ora1I6w43xPpj6fN3+mRu1k7QQFykDiTZSjZTD5QjC2g0MSVFG4Q1aqJZai1kfnN+PFB FzkbjxU0BbD7Fk6zZj4o1ooWyHIfrjw46/bO7+rbOR3ffc5ggsk2gwfPf/grsZZRYTZc lbWFOW3qfpI+R481ip4wiDqvEpCaMydIHoNBgL5ERCNperFk3cMeskNJYG5gripNAd+1 fqZafhv6oFnGIR4cwTCHhxkNdDmWsyckdyc2vUotjtytfKN+r4Y1g7YE5GTzG5mpZMI0 4pxg== X-Gm-Message-State: AOAM532Nn38cYe+3hQXuQemgWWYvg7sZtu+v7WztlqwggYSg+KWZfg81 8TNE4Nm+klceJSqnElrBE1cFgPPxBcc= X-Google-Smtp-Source: ABdhPJzRdSjXv4LbmOw4eV46oKXprUMeSKUuv2SItO74mCmEQJFDyIt3+maR6ckEe2AnHmrC8JrKaQ== X-Received: by 2002:a17:906:128e:: with SMTP id k14mr4192249ejb.485.1623922305949; Thu, 17 Jun 2021 02:31:45 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:45 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 15/45] softmmu/physmem: Mark shared anonymous memory RAM_SHARED Date: Thu, 17 Jun 2021 11:31:04 +0200 Message-Id: <20210617093134.900014-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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_size, } } -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 = qemu_ram_is_shared(new_block); RAMBlock *block; RAMBlock *last_block = NULL; ram_addr_t old_ram_size, new_ram_size; @@ -2084,7 +2085,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, return NULL; } - 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 |= RAM_PREALLOC; } + if (share) { + new_block->flags |= RAM_SHARED; + } if (resizeable) { new_block->flags |= 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); From patchwork Thu Jun 17 09:31:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99AB3C2B9F4 for ; Thu, 17 Jun 2021 09:40:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 496E561209 for ; Thu, 17 Jun 2021 09:40:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 496E561209 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoVf-0003Xc-0h for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:40:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNJ-0002l5-Uk for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:50 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:34439) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNH-00068r-Us for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:49 -0400 Received: by mail-ed1-x52a.google.com with SMTP id z12so3098688edc.1 for ; Thu, 17 Jun 2021 02:31:47 -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=jempworfNSeLBXZqL1QYZwHbPUXKSHYksUwRgxPhDCk=; b=UVyDblc76pFLLHP8PKq/IlzZfb3OjNLnD+JghWeNTYcKEtofH7xQTZCsmRAM/ajYCo hhuj0YCS7Sdza1Wmot6NYkAez7TPo5nKbd7BH8X/BESe91VXPFlyJFu1rblvLlgd8riJ VV4Re1xtzTc7To58AFVKZb+DfP9avSh66luYw5HVnz9xY8DNMXUaIn8PNYXuDDlhwVDd 9KImxQCGoeN6UImeU/9MzeLA2EzxVICX5y1xEtkggU1GnpTEVqexjtQCX36xLGwKGgH1 //yVj+JHSKxARL9UCZURJPaLmoUgklXi25es/EYrv1QBxQohOQ/M3A685kWo1VR+Q9VP sZuw== 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=jempworfNSeLBXZqL1QYZwHbPUXKSHYksUwRgxPhDCk=; b=kNPLl/b3QEXJPPpACJ8bLFiL+uq5DbI48lGaNv5OIItdP7DpAtIrB8DZ6fY3XrJYl2 3AwYxRacDFN0UyYmRHq5PlExkac2m1+kiG8jdwClfE9OJr4+DF+xl6/fyJmL7sjPo3Td ENBJKMkxlZ0GbwqcqbP4nGiGJ0wVQDTf4biIY3wG5RIdpV9U+Bh67wejIcmQjevO8osN eJF0j5t+OS0PqhRXgLp+nbY7o7/7Vh3xedIwDut4aigQetsg1BMi9SZvOrKWF/UgpuT+ U7QZNvG5SWzQtqlemYdcUSs3VmXQO/SYU0sjZvpDTAkevIFLbKBS4HloMqg594+cDrex SLcg== X-Gm-Message-State: AOAM531LRWy3JoK25Lb8CFRzVRu7nmXgdmPAmNZtELUCjGCX6LC0RZQy 9Iv86Rr2gt3rfcsBmeyqX7ONARPiJKE= X-Google-Smtp-Source: ABdhPJwoGruPBrAr9fbGCx9R+ZDpXiAejhyS2VRoudjYU8zSJBmYAbGdKJeozwBICVOi6yX7WPW2vg== X-Received: by 2002:aa7:cc19:: with SMTP id q25mr5233922edt.56.1623922306630; Thu, 17 Jun 2021 02:31:46 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 16/45] softmmu/physmem: Fix ram_block_discard_range() to handle shared anonymous memory Date: Thu, 17 Jun 2021 11:31:05 +0200 Message-Id: <20210617093134.900014-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand We can create shared anonymous memory via "-object memory-backend-ram,share=on,..." 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 --- include/qemu/osdep.h | 4 ++-- softmmu/physmem.c | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 236a045671..18a9e3fb4c 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -410,7 +410,7 @@ void qemu_anon_ram_free(void *ptr, size_t size); #ifdef MADV_REMOVE #define QEMU_MADV_REMOVE MADV_REMOVE #else -#define QEMU_MADV_REMOVE QEMU_MADV_INVALID +#define QEMU_MADV_REMOVE QEMU_MADV_DONTNEED #endif #elif defined(CONFIG_POSIX_MADVISE) @@ -424,7 +424,7 @@ void qemu_anon_ram_free(void *ptr, size_t size); #define QEMU_MADV_DONTDUMP QEMU_MADV_INVALID #define QEMU_MADV_HUGEPAGE QEMU_MADV_INVALID #define QEMU_MADV_NOHUGEPAGE QEMU_MADV_INVALID -#define QEMU_MADV_REMOVE QEMU_MADV_INVALID +#define QEMU_MADV_REMOVE QEMU_MADV_DONTNEED #else /* no-op */ diff --git a/softmmu/physmem.c b/softmmu/physmem.c index b78b30e7ba..c0a3c47167 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -3527,6 +3527,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, 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 = (rb->page_size == qemu_host_page_size); need_fallocate = rb->fd != -1; @@ -3560,7 +3561,11 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length) * fallocate'd away). */ #if defined(CONFIG_MADVISE) - ret = madvise(host_startaddr, length, MADV_DONTNEED); + if (qemu_ram_is_shared(rb) && rb->fd < 0) { + ret = madvise(host_startaddr, length, QEMU_MADV_REMOVE); + } else { + ret = madvise(host_startaddr, length, QEMU_MADV_DONTNEED); + } if (ret) { ret = -errno; error_report("ram_block_discard_range: Failed to discard range " From patchwork Thu Jun 17 09:31:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7FE1C2B9F4 for ; Thu, 17 Jun 2021 09:58:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 96655611CE for ; Thu, 17 Jun 2021 09:58:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96655611CE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:34266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoml-00014J-Lt for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:58:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNK-0002l6-58 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:50 -0400 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]:38477) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNI-00069Z-Lq for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:49 -0400 Received: by mail-ej1-x635.google.com with SMTP id og14so8737600ejc.5 for ; Thu, 17 Jun 2021 02:31:48 -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=o3h69v9GOdvNM0T/T0af/wQPPZJrIt2ocjfiNDFl060=; b=vFU9nKaebZGli3ris1n12ltnavzH/Rsq74xQmb9eHfiNc5wWv/eWU3Pt0Dj69XkRA3 PkNALsuT9bs8yISAMxOPcXunY2A3lW5ZHhVWl8NMKyofyTSoxqzinZwyP6PM1itoIdGe lwugy+2zS8lA015T6R6h7MUCGQZjJCD7ipz2VwYbB9o1Y71x55PAu0+RUaAeYTXhG5sb /P8kxAKNGpHtD3++76Efp/ljgIHjmIGZSQFRtINGgpUqo+1QIZ/0Q6jPSGZ38TS0+opI cyOicTHCYcFY7sA3SsYSexjRjU3XPi0ORgEN6eJCRrXAwHNF14lmbxkcIBZuKmYgV/eE ZjCQ== 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=o3h69v9GOdvNM0T/T0af/wQPPZJrIt2ocjfiNDFl060=; b=aKVcN9//p4Y139ondSYx/bthDqEZUmVp+vUwVMc6Kr1NPxpUibUAmrJfsPSbDXFNQC ZZ9N54EVWyK8t7CdqYBsWvVwLegQ40VUv8YW7p+g7qgJ4IRrtw4bg1zKg4MlKMZ7hVZB PsgWnf+0oAqAjrK953+FmCp9KmNaPzyos51FJu9FQSi5YjRpnOoGKeea0y2O85CqdBB9 JDgq6BJ0zijNZeEC0apwGyR270vCbU/ftjhR+WwKniNGD97mHBHw8AYuNf5joXuIRGt/ sSKmteUBSCYAFoh/8f2JCM4XiCb5jULvMSbzj0Du+LPE32NalZtiCoe65Z4rBkbp4jBs 2+hA== X-Gm-Message-State: AOAM533by8nFrBUhwIgmoTxnyHvXHhrOIkcGE4MI1bkO4zGA6yXOfDOv 7X3E5wo5f+1+tC6Vt52S6Tp7gRGG5sU= X-Google-Smtp-Source: ABdhPJzpRnb2OTaS1bNGFlbicDL2J1qM4KcbHsQxbaBky6V7LbqUj86pk5RqdtqJ8NAxUh/eZmrI2w== X-Received: by 2002:a17:907:9fd:: with SMTP id ce29mr4145823ejc.62.1623922307340; Thu, 17 Jun 2021 02:31:47 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 17/45] softmmu/physmem: Fix qemu_ram_remap() to handle shared anonymous memory Date: Thu, 17 Jun 2021 11:31:06 +0200 Message-Id: <20210617093134.900014-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 c0a3c47167..b75d205e8a 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2243,13 +2243,13 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) abort(); } else { flags = MAP_FIXED; + flags |= block->flags & RAM_SHARED ? + MAP_SHARED : MAP_PRIVATE; if (block->fd >= 0) { - flags |= (block->flags & RAM_SHARED ? - MAP_SHARED : MAP_PRIVATE); area = mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, block->fd, offset); } else { - flags |= MAP_PRIVATE | MAP_ANONYMOUS; + flags |= MAP_ANONYMOUS; area = mmap(vaddr, length, PROT_READ | PROT_WRITE, flags, -1, 0); } From patchwork Thu Jun 17 09:31:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFB7CC2B9F4 for ; Thu, 17 Jun 2021 09:45:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA175613DB for ; Thu, 17 Jun 2021 09:45:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA175613DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoaQ-0000RR-ON for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:45:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNO-0002no-UF for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:54 -0400 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:44746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNJ-00069g-MO for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:51 -0400 Received: by mail-ed1-x532.google.com with SMTP id u24so3018428edy.11 for ; Thu, 17 Jun 2021 02:31:48 -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=oEdOZ5K70QUWMpD6FIbQ9SgeKensv7aJzBbtlEVVVx/BXdZCpCjSZH4E/9XRfEifXw xJXPqHketGalVX0oAvS4XrFjNvcSeePG1W0Lu5dTgxyJO152XYsZha4JYc2UbsyOtRqw AADNS6tRs9+y/tMJO4Fa3jS+p8BHp64W7fRW2MYHkF6KG+UtFW7hiLGnie78Bp18ZOFF kdfabReygcTAzjdscWLotyC3x3CXI5uU9Az6xiJPNcLpN6A60xX4CbTHze4kCMbATEF9 uyutJeaK6IHO/hfJEceIiBI1FdnI2PRlPrU1dduNRAcLnqGDhvA8ogsTWLdBjMZzso/l ch4w== 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=fEoEKoExK1K14oZkq3eiho75bsIB+dQ7kp+GW9B7jM4HXcE6Q4LCwJ85abHzjEpvK6 E1P4quB9slEhZTdxWR70r2ruoINWMX4Pk9MkIb7tGfSiUhng39cMliBsS7S6lLQlaM+I RUz3aDs8p2HB88393SgfZsMrGoyPB/aC9JC9Rz71+gKZRGVlSdpQWa2aK4di/CHf/8hr 66SIYs6+KUmEHQWpIDhQ8mO50Pxf+JdfB15We9/c/Lm0r+2jYD2jHE5kTscnYv300+xb 5LKp8qz5x5vKbhx8CDZlIE3E64veq7Ukz/hnYKw8/rg+rjy53Qmy3Ld6nX9gREfIzqG+ 4yJg== X-Gm-Message-State: AOAM532jjz0hyqEAUXQ0B7G0OPuIDXVV2m0NVa3mR37xROq5LSTIl15d gC7t+Hk8m07p9xhp6DFzrTJq2FeX3oU= X-Google-Smtp-Source: ABdhPJyRaYuHjon4hq3BotWgWAeb+8aS5EMJmJSpAe64y1y2qlELS+U4S+eS0cRFi0h4hKZNStCg9g== X-Received: by 2002:a50:fc9a:: with SMTP id f26mr5148835edq.216.1623922308118; Thu, 17 Jun 2021 02:31:48 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:47 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 18/45] util/mmap-alloc: Factor out calculation of the pagesize for the guard page Date: Thu, 17 Jun 2021 11:31:07 +0200 Message-Id: <20210617093134.900014-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x532.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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 machine 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; } +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 = mmap_guard_pagesize(fd); int prot; int flags; int map_sync_flags = 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 = MAP_PRIVATE; - pagesize = qemu_fd_getpagesize(fd); - if (fd == -1 || pagesize == qemu_real_host_page_size) { + if (fd == -1 || guard_pagesize == qemu_real_host_page_size) { guardfd = -1; flags |= MAP_ANONYMOUS; } else { @@ -126,7 +135,6 @@ void *qemu_ram_mmap(int fd, } #else guardfd = -1; - pagesize = qemu_real_host_page_size; flags = MAP_PRIVATE | MAP_ANONYMOUS; #endif @@ -138,7 +146,7 @@ void *qemu_ram_mmap(int fd, assert(is_power_of_2(align)); /* Always align to host page size */ - assert(align >= pagesize); + assert(align >= guard_pagesize); flags = MAP_FIXED; flags |= fd == -1 ? MAP_ANONYMOUS : 0; @@ -193,8 +201,8 @@ void *qemu_ram_mmap(int fd, * a guard page guarding against potential buffer overflows. */ total -= 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); } return ptr; @@ -202,15 +210,8 @@ void *qemu_ram_mmap(int fd, 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 = qemu_fd_getpagesize(fd); -#else - pagesize = qemu_real_host_page_size; -#endif - munmap(ptr, size + pagesize); + munmap(ptr, size + mmap_guard_pagesize(fd)); } } From patchwork Thu Jun 17 09:31:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327151 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 997CDC2B9F4 for ; Thu, 17 Jun 2021 09:42:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3303D613DB for ; Thu, 17 Jun 2021 09:42:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3303D613DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoXf-0001VH-Ay for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:42:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNO-0002nx-WF for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:55 -0400 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]:46739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNK-0006AH-7E for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:51 -0400 Received: by mail-ed1-x52d.google.com with SMTP id s15so3015466edt.13 for ; Thu, 17 Jun 2021 02:31:49 -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=Y/dRO7uHPmJWmEZDzAC0CdLggjBnok+5WFoctspVAzsJi854u56VYoqcKJdYCtg/iD J2Ogco2yXKzDKmmsDYP6CrG3CBh5j8FLpk+wspLtkBNrs750AJEttJglLARGod2Sk6Xi oiJpG/NWZDzhyX6wqJYt73/CXJL8UFcmZfMbTnoH2fTIBdaoFs3QLIOnXW6I3U7BXWVZ ExUGqDK7aXofVHofnT1q4qPbMwoG2MHjMzHcw83qf81wJevWGH48agWzRL/hqMjus+18 lVjuM6qUdIlAR2ppEBfUJXw7lL/gp+eJ1pMetg750oNXCve4+NhIvIHsRUEBOc44sCd1 4poQ== 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=SpgsoQ0Rw8oaNCIuvNHd94YDBK2wHIAquyUkAFArJcz9qEGKiA93kFfalgT32u/Bx+ Vb9kt4irv6TA1LVudamRFZSsey/OFmhrndh8M8DQyAsH7jZVuFR7Cp3PwEbrX/CHHu1E JYuWt7tSemJOuRdocwbFQJyjaHsQLpzzT753EV6pN0kmKtQlDkm1llKXLcHunwJemBNr b3HUUtfUCuVJiFU0vhjb1X5YcJYdqa2xYOycjPdl5E2rvd/WL+jwciNPQDogXFE6+iiv Z4CcRz2cXWshMGHYexGCXoEf0Kp3mU8omKsIpJYq1xqGOZf+piI0tXLQ6JkVVEw0CioU WdNw== X-Gm-Message-State: AOAM530NL7spnUcRwdD5bXN2YBKF+J/03l7nuTs4ElLaaigcAJ4cohEF k8g6bWiYDo2TQ3N2nnvk5SFd7DOCO2g= X-Google-Smtp-Source: ABdhPJxATh9QgtTRzDuKplu6nWWC1cuZP17ekTi3OUAM6ggfzersLOpdIaYh4LP3vqt7fCuymnr5mA== X-Received: by 2002:a05:6402:35cc:: with SMTP id z12mr5297671edc.45.1623922308975; Thu, 17 Jun 2021 02:31:48 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:48 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 19/45] util/mmap-alloc: Factor out reserving of a memory region to mmap_reserve() Date: Thu, 17 Jun 2021 11:31:08 +0200 Message-Id: <20210617093134.900014-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52d.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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 machine 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; } +/* + * 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 = MAP_PRIVATE; + +#if defined(__powerpc64__) && defined(__linux__) + /* + * On ppc64 mappings in the same segment (aka slice) must share the same + * 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 == -1 || qemu_fd_getpagesize(fd) == qemu_real_host_page_size) { + fd = -1; + flags |= MAP_ANONYMOUS; + } else { + flags |= MAP_NORESERVE; + } +#else + fd = -1; + flags |= 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 = 0; - int guardfd; size_t offset; size_t total; void *guardptr; @@ -116,30 +147,7 @@ void *qemu_ram_mmap(int fd, */ total = size + align; -#if defined(__powerpc64__) && defined(__linux__) - /* On ppc64 mappings in the same segment (aka slice) must share the same - * 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 = MAP_PRIVATE; - if (fd == -1 || guard_pagesize == qemu_real_host_page_size) { - guardfd = -1; - flags |= MAP_ANONYMOUS; - } else { - guardfd = fd; - flags |= MAP_NORESERVE; - } -#else - guardfd = -1; - flags = MAP_PRIVATE | MAP_ANONYMOUS; -#endif - - guardptr = mmap(0, total, PROT_NONE, flags, guardfd, 0); - + guardptr = mmap_reserve(total, fd); if (guardptr == MAP_FAILED) { return MAP_FAILED; } From patchwork Thu Jun 17 09:31:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94216C48BE5 for ; Thu, 17 Jun 2021 09:48:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C583613BF for ; Thu, 17 Jun 2021 09:48:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C583613BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltodU-0006G5-9C for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:48:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNR-0002rJ-35 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:58 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:45598) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNM-0006Ar-OW for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:56 -0400 Received: by mail-ed1-x52f.google.com with SMTP id r7so3016122edv.12 for ; Thu, 17 Jun 2021 02:31:50 -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=a4gAdIymstt98imS5Cx+cdFYsrLWt8PxrffQqIficYfqF5Qrz7a1UyaKQlMmyjkg6a v2jGgmgrxGdPrtcZsXpDF+8+KPtB7UsX+pJpYY+WxWvuBavGuvt3HoFQKzoTGFbHsvHa kTJoiasmwIJ324m0GvbrSVTj54vqSPqN2hQ95IDC0+lGo7zBS3PR9U/m7Am1llXw6NBf tMfcBAsv7ytag1elSPq8S1AhUj/sayiRajeCSeywBSbI1ZRJ+rKYnQ4H+1dgW8PVqPT4 vyWnslcEbFexahTKqwTK1GeNw33O228S7Ldz4USZys+3xUtXP1bpt5rEDbU9BfuwAFdn lxsg== 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=bUL2/6heFSvmw9JkqpIC5n2rhFTZH99An5nUk6D5UWD5PR3SiDHvFQncIkrHPnI4TV 6o9/9q2GK4dfBfS/+7EtU1hOMfrwkdUPFIAikNPuP1S9Bb9oaDGBbXUfNRLevMX8A/+v Nph9nRtaT6CVD+mKS+44M2/qbk+beVFoQs3t79Ic4fzhafk3B3VHQb+GP239WOqSK4jF 4NC0DT5ASjt3kEQmT4Uv83Qg9cpVSwY3oF0A7uFcppcXO+r0mT1IVe+eB/fR+B7FaoYr wdldir3xC1LahRTDd8iXt8u1L5inRVmgnqmHSDAAT6NFpraKBIEWz/yRy+0vmA11PvXM mD2A== X-Gm-Message-State: AOAM532+/JQOjx6oXylrpyf1oLaQTeH7k4VndE/LEBn7YIqe5Cel+irw 07DQz4ThUYQ3J/GVo4/+zcr4l/+l0N4= X-Google-Smtp-Source: ABdhPJycg246I3U4KrjDnTQVkCFR/hjMU5kdXQGJ7E6vYXiT/HR80lRp1E5Kh1Oe31leAsqQ7Ngkxg== X-Received: by 2002:aa7:d892:: with SMTP id u18mr5366258edq.196.1623922309751; Thu, 17 Jun 2021 02:31:49 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 20/45] util/mmap-alloc: Factor out activating of memory to mmap_activate() Date: Thu, 17 Jun 2021 11:31:09 +0200 Message-Id: <20210617093134.900014-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 machine 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); } +/* + * 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 = PROT_READ | (readonly ? 0 : PROT_WRITE); + int map_sync_flags = 0; + int flags = MAP_FIXED; + void *activated_ptr; + + flags |= fd == -1 ? MAP_ANONYMOUS : 0; + flags |= shared ? MAP_SHARED : MAP_PRIVATE; + if (shared && is_pmem) { + map_sync_flags = MAP_SYNC | MAP_SHARED_VALIDATE; + } + + activated_ptr = mmap(ptr, size, prot, flags | map_sync_flags, fd, + map_offset); + if (activated_ptr == MAP_FAILED && map_sync_flags) { + if (errno == ENOTSUP) { + char *proc_link = g_strdup_printf("/proc/self/fd/%d", fd); + char *file_name = g_malloc0(PATH_MAX); + int len = readlink(proc_link, file_name, PATH_MAX - 1); + + if (len < 0) { + len = 0; + } + file_name[len] = '\0'; + fprintf(stderr, "Warning: requesting persistence across crashes " + "for backend file %s failed. Proceeding without " + "persistence, data might become corrupted in case of host " + "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 = 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 = mmap_guard_pagesize(fd); - int prot; - int flags; - int map_sync_flags = 0; - size_t offset; - size_t total; - void *guardptr; - void *ptr; + size_t offset, total; + void *ptr, *guardptr; /* * Note: this always allocates at least one extra page of virtual address @@ -156,45 +197,10 @@ void *qemu_ram_mmap(int fd, /* Always align to host page size */ assert(align >= guard_pagesize); - flags = MAP_FIXED; - flags |= fd == -1 ? MAP_ANONYMOUS : 0; - flags |= shared ? MAP_SHARED : MAP_PRIVATE; - if (shared && is_pmem) { - map_sync_flags = MAP_SYNC | MAP_SHARED_VALIDATE; - } - offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; - prot = PROT_READ | (readonly ? 0 : PROT_WRITE); - - ptr = mmap(guardptr + offset, size, prot, - flags | map_sync_flags, fd, map_offset); - - if (ptr == MAP_FAILED && map_sync_flags) { - if (errno == ENOTSUP) { - char *proc_link, *file_name; - int len; - proc_link = g_strdup_printf("/proc/self/fd/%d", fd); - file_name = g_malloc0(PATH_MAX); - len = readlink(proc_link, file_name, PATH_MAX - 1); - if (len < 0) { - len = 0; - } - file_name[len] = '\0'; - fprintf(stderr, "Warning: requesting persistence across crashes " - "for backend file %s failed. Proceeding without " - "persistence, data might become corrupted in case of host " - "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 = mmap(guardptr + offset, size, prot, flags, fd, map_offset); - } - + ptr = mmap_activate(guardptr + offset, size, fd, readonly, shared, is_pmem, + map_offset); if (ptr == MAP_FAILED) { munmap(guardptr, total); return MAP_FAILED; From patchwork Thu Jun 17 09:31:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E602C2B9F4 for ; Thu, 17 Jun 2021 09:51:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB6066113C for ; Thu, 17 Jun 2021 09:51:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB6066113C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltog2-0002tg-SL for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:51:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNT-0002t8-5R for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:59 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:40913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNO-0006CK-MX for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:58 -0400 Received: by mail-ed1-x52a.google.com with SMTP id t3so3044404edc.7 for ; Thu, 17 Jun 2021 02:31:51 -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=qMdJfx6V9bOaKTvFQ5B+WZCzcOWle9vbgsfQILeMuJ4ztbDnvaOuRnsXXbLNrQ82Ou SDHXWOEJmsIJqenSgytEabDWSgKd4bDhgUsronM1NsuKe6ugGz085yx1sD5s7u1bCMmL SFoZmB2wKnqFoEmPm5aBpbn9VNO1f0NF5Tb4WmDCUANXodBfQDxpazvF/vjsQ+HZgd4C cSzRFSzSSxVt1cNLRSAZQkI3U/aa9t2lDmN8nJ5jODM8WrRakQKWuqg3B3CnY4Yr6p5S Q7snob7MTI/XVqkzwkO/pV6hH6/MtkWrE4nZr0H5OHiPm/RXfw8Qw1rp4VdquYo9E19t 6sxw== 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=ti86r/NES32fiyvehSgawUAFIO/DUgi4n+z0hOwDSHsCWANDZ+zRAmm3s6Ntg/4Gj5 Va2DTh/Oz4DcBZNW9kwko4963BBmr/Z1EEgEa/lC2YdFUz3kKy4EThMy9uTTR6OgyGc4 C0tSrWfxrIH4pieGmsHvsqDiA20qW+lFPTOOgPgCSR0ggq6leCsbB5QQDvvkRoraTUuD L0/1d6INPbKHN3rHP7ccFW1GzgaacVGx33ws+2t2C8Z7vzY/oO0yNuHAR3ke478MSZe+ KJUi2FuNVAfztBGtBIFcoyfAGsadojRqNw67Ha5iyOmOqBR9RPUs4pKO5chxGHmKEUgQ EZww== X-Gm-Message-State: AOAM531BxeUhzgUXF4rmUHjb2qP2lQ6mjhAUc9yYykndVpRvdSxRpttk n1mLh0byy2FNVsVhbpoyU7upgTyqo0Y= X-Google-Smtp-Source: ABdhPJyaoQIqgUTb8h+63gkFqpI93kJvfrQfZUZuvysiJgsHx3sqQSqy/CPri6U9Bvxv0twOAHmegQ== X-Received: by 2002:a05:6402:11cc:: with SMTP id j12mr5319112edw.114.1623922310541; Thu, 17 Jun 2021 02:31:50 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 21/45] softmmu/memory: Pass ram_flags to qemu_ram_alloc_from_fd() Date: Thu, 17 Jun 2021 11:31:10 +0200 Message-Id: <20210617093134.900014-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.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.248, 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_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and machine 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 = MEMORY_BACKEND_MEMFD(backend); + uint32_t ram_flags; char *name; int fd; @@ -52,9 +53,9 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) } name = 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 = 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); } 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 = buf.st_size; /* 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.bar2", + 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 alignment * (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 *mr, * @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_SHARED - * - RAM_PMEM: the backend @mem_path or @fd is persistent memory - * 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 = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc_from_fd(size, mr, - share ? RAM_SHARED : 0, - fd, offset, false, &err); + mr->ram_block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, offset, + false, &err); if (err) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); From patchwork Thu Jun 17 09:31:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19376C2B9F4 for ; Thu, 17 Jun 2021 09:44:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99BB461209 for ; Thu, 17 Jun 2021 09:44:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99BB461209 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoZq-0007DN-Oe for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:44:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNR-0002ra-5w for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:58 -0400 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:38899) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNO-0006Cg-Nq for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:56 -0400 Received: by mail-ed1-x529.google.com with SMTP id t7so3047392edd.5 for ; Thu, 17 Jun 2021 02:31:52 -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=JYTxUEgSplGZy/0CFjEJzFB97DeABZjD9i05RTj8h9Fp48nOM5QGubUhP2CEsQa8L+ dGJgzepz8QlCGtMuuPE1RLkkCa0f7fWiAJAnJvhzrpOtx3PcMgLVMKschIdNtCVwsUcT E4viKqGYyfYyPLvShQY3zf4PvSGA8rZR7Movuqq7h0uqSKyb/4+jgORPbTuVgVlh2HEj sIRKKJf6zmH9axCUL1YVlENoOs8aMcAMQ8er9I9SC7vkI5HSrtsVzXCjk3TxzQypPx9u FGnb92DCLqixMg/97khp++vZ89ecYzfiejhV0yevDJY+OHXHkon8jYIWbBR9PQORURJJ dzzQ== 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=IW3Ep8g9WiZdmAoI6YIMXgjVEJgsKI8GV8gcFWhxLLJrGqCiFWgbYJ0x4VS6bsDYlH 6Fju1mpA6II1bqnEn3ALfmpu3MAEJhidTwQlhBx446ILy7JH24OJ+HzgnkHwmu1g1gFw mdAEtWQpbtw+ExOEGpQ60e/obUWXOva3AN7GwOBxz7D86BsOiPZNjIxqddGdAEvfJ91l Rt+DJM6TMonrZHtFz7nhi0frbwGVCdVZus2KBFwKOGD4XzRx9HIZYeRRZ/dEJvLpkimR EqjNHZWjgsyTBVydspFU6QzA4bZ52XzBoYXCc0flqOKWg8PhiRnd57r3NI7UGQl0CSqF qNHQ== X-Gm-Message-State: AOAM530Et4LtnZ5e69MdFr0k33m6G7KAgxystYt8TpASM3058u9ErnPP IIZ5k3Koa1GcnlfMRWzxbvya5EhG5BI= X-Google-Smtp-Source: ABdhPJwKpKHBBIxVYkuKKBiU0frMaLpRGPI/2ucd/5tOauXH9P/4sHqqWJ7gWwafbEvr4W7IXT8guQ== X-Received: by 2002:a05:6402:4c:: with SMTP id f12mr5383635edu.84.1623922311449; Thu, 17 Jun 2021 02:31:51 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 22/45] softmmu/memory: Pass ram_flags to memory_region_init_ram_shared_nomigrate() Date: Thu, 17 Jun 2021 11:31:11 +0200 Message-Id: <20210617093134.900014-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::529; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x529.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.248, 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_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and machine 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; if (!backend->size) { @@ -27,8 +28,9 @@ ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) } name = host_memory_backend_get_name(backend); - memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), name, - backend->size, backend->share, errp); + ram_flags = backend->share ? RAM_SHARED : 0; + memory_region_init_ram_flags_nomigrate(&backend->mr, OBJECT(backend), name, + backend->size, ram_flags, errp); g_free(name); } 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); /* 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", 64, + 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, 64); 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 *mr, Error **errp); /** - * 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 stream * 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 caller. */ -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); /** * memory_region_init_resizeable_ram: Initialize memory region with resizeable 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); } -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 = NULL; memory_region_init(mr, owner, name, size); mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc(size, share, mr, &err); + mr->ram_block = qemu_ram_alloc(size, ram_flags & RAM_SHARED, mr, &err); if (err) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); @@ -1682,7 +1682,7 @@ void memory_region_init_rom_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); mr->readonly = true; } From patchwork Thu Jun 17 09:31:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327149 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D65DC2B9F4 for ; Thu, 17 Jun 2021 09:42:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A42E061209 for ; Thu, 17 Jun 2021 09:42:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A42E061209 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoXU-0000pm-MX for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:42:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNT-0002tP-8d for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:59 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:44745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNO-0006Cm-OQ for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:58 -0400 Received: by mail-ed1-x530.google.com with SMTP id u24so3018702edy.11 for ; Thu, 17 Jun 2021 02:31:53 -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=FX5w3RkTBMk4kaoFI+sw3zf8MxzufRUDXXzqaE5j/1g=; b=M6amcrEgnFymbylavUYXAl+t871TVZacUnEE3jNnZV+z0SYv5QieKnGOo/GSNv8yYY P3o8Hm8uTsoFCK6zqsudB5iU6EI0NQf9HkIfG5INtBA2SbcYOJp1eTzDOR16vLErlMEX I9/Ati/itgWy8IivGYwXxdbN1AgtVXfI2y5aFLonEOcPBVHX1dMxokd97/dfqg7+bjvi 31ULT3+KesE52vdNH0U+szTrGTVAAqdAPgb41VIFlDD7zoMA+X/yzyleyntokebFh5cw aYrV1c6gnwoi4ZQULif0vxThw+uAsS3Yr4WBBFLJ6VDqmP0ySvnlodfnt67+xGi0U5VY nA4w== 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=FX5w3RkTBMk4kaoFI+sw3zf8MxzufRUDXXzqaE5j/1g=; b=oAUWmWpbRL2nwXocDl8oFPLgYKNPeKg+2MAFGh3d2u8y8JLpzMX3sqeXKc2ZP/nN+X AadhAHJSenTXn5I+dXyRwaswxy13GgwMVbexBUNgqKzabLf3YDLXUQW+abYWpvkPpcl0 i/PSvRp5r7L3GF35j3eEFXQikSPaKdT/VH4fS7jZzeFUmPkHF2SVBXzjrz8NUbuxLDoO ilqow+w2xqVsKuWVkZoULaIMRFYKzvpRNeevb7FWzrsBC/N0KW4NF0V2WSp5VCADH6p0 /v/uHfcW1gbmfLjEPrCVvFlUiiT+pINw27LAOoMZrJlkx4VtB3hkP1+SjG2Zu3jS1Wp2 0dPg== X-Gm-Message-State: AOAM533qRYk6S4sZWViR07CUjEX1ETmPmOGg2kMpgcd2SRsVl/E3KVdV Ex5J7UaNFo92YSM/btP8NPILltsej+E= X-Google-Smtp-Source: ABdhPJwTozhipwUnHpG4EMQcqX9ZRZK5iu9/TktZIn3WimFQXOIa/Y9XO0h0HsnI7yTValAATBUhog== X-Received: by 2002:a05:6402:4255:: with SMTP id g21mr5251143edb.103.1623922312208; Thu, 17 Jun 2021 02:31:52 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:51 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 23/45] softmmu/memory: Pass ram_flags to qemu_ram_alloc() and qemu_ram_alloc_internal() Date: Thu, 17 Jun 2021 11:31:12 +0200 Message-Id: <20210617093134.900014-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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_Mathieu-Daud=C3=A9?= , Eduardo Habkost , David Hildenbrand Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Acked-by: Eduardo Habkost for memory backend and machine 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, MemoryRegion *mr, 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(MemoryRegion *mr, mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc(size, ram_flags & RAM_SHARED, mr, &err); + mr->ram_block = qemu_ram_alloc(size, ram_flags, mr, &err); if (err) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); @@ -1702,7 +1702,7 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->rom_device = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc(size, false, mr, &err); + mr->ram_block = qemu_ram_alloc(size, 0, mr, &err); if (err) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); diff --git a/softmmu/physmem.c b/softmmu/physmem.c index b75d205e8a..f00304e254 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 = NULL; + assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0); + assert(!host ^ (ram_flags & RAM_PREALLOC)); + size = HOST_PAGE_ALIGN(size); max_size = HOST_PAGE_ALIGN(max_size); new_block = g_malloc0(sizeof(*new_block)); @@ -2145,15 +2148,7 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size, new_block->fd = -1; new_block->page_size = qemu_real_host_page_size; new_block->host = host; - if (host) { - new_block->flags |= RAM_PREALLOC; - } - if (share) { - new_block->flags |= RAM_SHARED; - } - if (resizeable) { - new_block->flags |= RAM_RESIZEABLE; - } + new_block->flags = 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, mr, + errp); } -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) == 0); + return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, errp); } 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); } static void reclaim_ramblock(RAMBlock *block) From patchwork Thu Jun 17 09:31:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA811C48BE5 for ; Thu, 17 Jun 2021 09:44:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3A6B7613DB for ; Thu, 17 Jun 2021 09:44:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3A6B7613DB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoZc-0006Xq-SA for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:44:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNT-0002tO-7a for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:59 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:43613) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNO-0006D8-OC for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:58 -0400 Received: by mail-ed1-x534.google.com with SMTP id s6so3021678edu.10 for ; Thu, 17 Jun 2021 02:31:54 -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=PxIimyH05wD1zkB/Bar1jOIFqkMaKCn4QuyiOagAX+Q=; b=DIqrH/nTvIaI5Twx9PKmofjrN7nRSlVfbIvNKa2UcWNB1cmPiHhA3w2azqpuKwQvGG lX0f5TSTOJg4FuOiG2EpGsqY0HhbYIhp4h4J2daK7hr2A+WR58hg5IWJ2CJtCAe4HDx3 TVFgeAGiu4CnobUMDYkfZHnyHcwmEzdTOJaJ/NRhlVw3yxoxJ6Rh0/jTMl2xon/zQ7E8 4QcGoF71gc0lAQ3JpEOb7jOZLQjwRn6Xeuj4FNUyvB4zLNizVkEX62c9O+3EI9qnVSkO GifkKzwR5rljNCIyn8u7qjVN6RZKDzDM3Nxdnb9D52TEnz265c7ySvzofcConJg5aEth DFwA== 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=PxIimyH05wD1zkB/Bar1jOIFqkMaKCn4QuyiOagAX+Q=; b=Senougb2xhkWaB5MO1koIH66HU3LhWr4Tlj9V19vS2St/iEkXUOO+YFgjNwuv2wMZU aIoVkX+4XhNhev+JrIed56ERlnkSgtuPwewr1H2roYs+FCitClnKo9m8kMkldEOFjrX4 txSxl1+TjZgEnyiTvxWdhCSLQLMDpDHzxl5uUiHiM14Ydl9f9NU0Dw4bnUT2carNKyJv WE3uUbYrAzCPnT371o4UIdSFrbN45aolCjh80a12mEzl2hCbWMBUMtx575rKapgELf+M OctxcnxxyIvBi/ye/EnNsOJNMGWkSXEwzZ55ZipfUI0Csg0lRnHSmo0jvo9lxwvoWf/n MZOw== X-Gm-Message-State: AOAM532kPO2iT4jTfwTjOrsH/EImcOStkoygAls+laH4diC0AQPKPqpr kbx88UkIBeDoHuM6G86kl5aHW3Lhkg0= X-Google-Smtp-Source: ABdhPJzAxtMA8GQIgbr98YzyLynZhJjLHz0P05DAgReQTAgHB7mc5ABvFxVQbnRfkXDFZzg98ETeBw== X-Received: by 2002:a05:6402:6c8:: with SMTP id n8mr5200449edy.180.1623922313112; Thu, 17 Jun 2021 02:31:53 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:52 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 24/45] util/mmap-alloc: Pass flags instead of separate bools to qemu_ram_mmap() Date: Thu, 17 Jun 2021 11:31:13 +0200 Message-Id: <20210617093134.900014-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x534.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.248, 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_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and machine 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); /** - * 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 address; * 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); void qemu_ram_munmap(int fd, void *ptr, size_t size); diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 18a9e3fb4c..37a38c4af3 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); +/* + * 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 #if defined(CONFIG_MADVISE) diff --git a/softmmu/physmem.c b/softmmu/physmem.c index f00304e254..a110aa67fd 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; block->page_size = qemu_fd_getpagesize(fd); @@ -1587,9 +1588,10 @@ static void *file_ram_alloc(RAMBlock *block, perror("ftruncate"); } - area = qemu_ram_mmap(fd, memory, block->mr->align, readonly, - block->flags & RAM_SHARED, block->flags & RAM_PMEM, - offset); + qemu_map_flags = readonly ? QEMU_MAP_READONLY : 0; + qemu_map_flags |= (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0; + qemu_map_flags |= (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0; + area = qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, offset); if (area == 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 = qemu_map_flags & QEMU_MAP_READONLY; + const bool shared = qemu_map_flags & QEMU_MAP_SHARED; + const bool sync = qemu_map_flags & QEMU_MAP_SYNC; const int prot = PROT_READ | (readonly ? 0 : PROT_WRITE); int map_sync_flags = 0; int flags = MAP_FIXED; @@ -128,7 +131,7 @@ static void *mmap_activate(void *ptr, size_t size, int fd, bool readonly, flags |= fd == -1 ? MAP_ANONYMOUS : 0; flags |= shared ? MAP_SHARED : MAP_PRIVATE; - if (shared && is_pmem) { + if (shared && sync) { map_sync_flags = MAP_SYNC | MAP_SHARED_VALIDATE; } @@ -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 = mmap_guard_pagesize(fd); @@ -199,7 +200,7 @@ void *qemu_ram_mmap(int fd, offset = QEMU_ALIGN_UP((uintptr_t)guardptr, align) - (uintptr_t)guardptr; - ptr = mmap_activate(guardptr + offset, size, fd, readonly, shared, is_pmem, + ptr = mmap_activate(guardptr + offset, size, fd, qemu_map_flags, map_offset); if (ptr == 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 = shared ? QEMU_MAP_SHARED : 0; size_t align = QEMU_VMALLOC_ALIGN; - void *ptr = qemu_ram_mmap(-1, size, align, false, shared, false, 0); + void *ptr = qemu_ram_mmap(-1, size, align, qemu_map_flags, 0); if (ptr == MAP_FAILED) { return NULL; From patchwork Thu Jun 17 09:31:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3147C2B9F4 for ; Thu, 17 Jun 2021 09:47:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7363A60D07 for ; Thu, 17 Jun 2021 09:47:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7363A60D07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltocE-0004eG-RM for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:47:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNT-0002tU-8d for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:59 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:41660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNP-0006De-Bt for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:58 -0400 Received: by mail-ej1-x62b.google.com with SMTP id ho18so8721148ejc.8 for ; Thu, 17 Jun 2021 02:31:54 -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=SU+cYe1FRwPKDSkSXS+knGVInNDUPwuMf49njV4Y8UU=; b=PfPg3TpxN3ha0tXXF1nYDzG37gQaPvkodQN3tbIgSKFCnnZsnxm4xGuybJC8XcyQc9 mz87j6G0x16ObbqO6aNb7uhUSOrYR+tSZjCHES/P5Ot8lI6HrTw8gQLPEeHP5RUi8ZTV of355HIDWe+LCR9JJNmnTh9pQBsIC6nIh095+UVWuo0GFILRnWf7Pb7XWa5cukmAmRHf qO6CnplNlKEQklp7RXbTi0mAG4MSZXNWq4A+MEHgU/URDdNLATzBoLXCfnm1q24BOLlb QUu9vpbtR6g2cZ7EBOsQFRv46jDSqSHn8PlbwJnbmzjcnFm/J7Ai5+Q2E/esbme1MN7U zUFQ== 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=SU+cYe1FRwPKDSkSXS+knGVInNDUPwuMf49njV4Y8UU=; b=kUbd/SpPAq97y9jQOPzSo/usn8hr2eaDRBk0sX8eIOoUFHG/dUrt4/rqmXbuc2Tncy UDyrYp4lIOtPFhjiYYD4KJWPlI59jakkFBN+zAJJcK8pIE/+h+ZdRoqZWovmKwOold/K V1AGwDtl2gBNX4xzvFTB0enmk62NF3Aen31N03cIhEPM2SMJR8EkHMzpPiorMMzoaFjS IQgEw/+4qPYmInR/rIQKs0xbybA2+3yw2CejIpdqK3Vx654UC5h53ArEHwrvqef8/qyD ynDmgpNX9/z6rHWLx/CjCONmWWik2iCUi0llgfKHiVqryAtUB4D0cBnJbQdRo+FUXxve 2OAA== X-Gm-Message-State: AOAM530/GzYBwerFqD8m3WfIPkTuZranm8a/Mnhr6vJKDVQu5c9zJXn0 0Hk71IHf8PkNUvUeMOy1x6oQhal+Fkk= X-Google-Smtp-Source: ABdhPJwqkuhMh/NnJlIJZAh2SjcTBviK5Ckiv4BbuHLwEq1ASq4sIMoKFZUX0qUypWbPmR4HlATtjA== X-Received: by 2002:a17:906:488f:: with SMTP id v15mr4167989ejq.428.1623922313924; Thu, 17 Jun 2021 02:31:53 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 25/45] memory: Introduce RAM_NORESERVE and wire it up in qemu_ram_mmap() Date: Thu, 17 Jun 2021 11:31:14 +0200 Message-Id: <20210617093134.900014-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Peter Xu , David Hildenbrand Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Peter Xu Acked-by: Eduardo Habkost for memory backend and machine 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) +/* + * 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. + */ +#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 stream * 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 alignment * (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 *mr, * @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 37a38c4af3..c2c7fe5c47 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); @@ -383,6 +384,12 @@ void qemu_anon_ram_free(void *ptr, size_t size); */ #define QEMU_MAP_SYNC (1 << 2) +/* + * 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) + #define QEMU_MADV_INVALID -1 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 = 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 block %s," "size 0x" RAM_ADDR_FMT, __func__, block->idstr, diff --git a/softmmu/physmem.c b/softmmu/physmem.c index a110aa67fd..11ea8e19a6 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -1591,6 +1591,7 @@ static void *file_ram_alloc(RAMBlock *block, qemu_map_flags = readonly ? QEMU_MAP_READONLY : 0; qemu_map_flags |= (block->flags & RAM_SHARED) ? QEMU_MAP_SHARED : 0; qemu_map_flags |= (block->flags & RAM_PMEM) ? QEMU_MAP_SYNC : 0; + qemu_map_flags |= (block->flags & RAM_NORESERVE) ? QEMU_MAP_NORESERVE : 0; area = qemu_ram_mmap(fd, memory, block->mr->align, qemu_map_flags, offset); if (area == MAP_FAILED) { error_setg_errno(errp, errno, @@ -1716,6 +1717,11 @@ bool qemu_ram_is_shared(RAMBlock *rb) return rb->flags & RAM_SHARED; } +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_size, static void ram_block_add(RAMBlock *new_block, Error **errp) { + const bool noreserve = qemu_ram_is_noreserve(new_block); const bool shared = qemu_ram_is_shared(new_block); RAMBlock *block; RAMBlock *last_block = NULL; @@ -1973,7 +1980,7 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) } else { new_block->host = 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, MemoryRegion *mr, int64_t file_size, file_align; /* Just support these ram flags by now. */ - assert((ram_flags & ~(RAM_SHARED | RAM_PMEM)) == 0); + assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_NORESERVE)) == 0); 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, ram_addr_t max_size, Error *local_err = NULL; assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC)) == 0); + assert((ram_flags & ~(RAM_SHARED | RAM_RESIZEABLE | RAM_PREALLOC | + RAM_NORESERVE)) == 0); assert(!host ^ (ram_flags & RAM_PREALLOC)); size = HOST_PAGE_ALIGN(size); @@ -2170,7 +2179,7 @@ RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, RAMBlock *qemu_ram_alloc(ram_addr_t size, uint32_t ram_flags, MemoryRegion *mr, Error **errp) { - assert((ram_flags & ~RAM_SHARED) == 0); + assert((ram_flags & ~(RAM_SHARED | RAM_NORESERVE)) == 0); return qemu_ram_alloc_internal(size, size, NULL, NULL, ram_flags, mr, errp); } 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" #define HUGETLBFS_MAGIC 0x958458f6 @@ -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 = qemu_map_flags & QEMU_MAP_NORESERVE; const bool readonly = qemu_map_flags & QEMU_MAP_READONLY; const bool shared = qemu_map_flags & QEMU_MAP_SHARED; const bool sync = qemu_map_flags & QEMU_MAP_SYNC; @@ -129,6 +131,11 @@ static void *mmap_activate(void *ptr, size_t size, int fd, int flags = MAP_FIXED; void *activated_ptr; + if (noreserve) { + error_report("Skipping reservation of swap space is not supported"); + return MAP_FAILED; + } + flags |= fd == -1 ? MAP_ANONYMOUS : 0; flags |= 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) } /* 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 = shared ? QEMU_MAP_SHARED : 0; + const uint32_t qemu_map_flags = (shared ? QEMU_MAP_SHARED : 0) | + (noreserve ? QEMU_MAP_NORESERVE : 0); size_t align = QEMU_VMALLOC_ALIGN; void *ptr = qemu_ram_mmap(-1, size, align, qemu_map_flags, 0); 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 /* this must come after including "trace.h" */ @@ -76,10 +77,20 @@ static int get_allocation_granularity(void) return system_info.dwAllocationGranularity; } -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; + if (noreserve) { + /* + * We need a MEM_COMMIT before accessing any memory in a MEM_RESERVE + * area; we cannot easily mimic POSIX MAP_NORESERVE semantics. + */ + error_report("Skipping reservation of swap space is not supported."); + return NULL; + } + ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE); trace_qemu_anon_ram_alloc(size, ptr); From patchwork Thu Jun 17 09:31:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0826C2B9F4 for ; Thu, 17 Jun 2021 10:02:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 31D9B61003 for ; Thu, 17 Jun 2021 10:02:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31D9B61003 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoqY-0000Yv-7U for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:02:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNT-0002tH-5u for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:59 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:35400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNP-0006Ez-TH for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:58 -0400 Received: by mail-ed1-x52c.google.com with SMTP id df12so568094edb.2 for ; Thu, 17 Jun 2021 02:31:55 -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=HN1jSml8xGVKMU1qgeTlmdidtub7pA6wErpj5PAwFrg=; b=lscF1YrDLgTMq3vchBgYRukwJnaobz/s255t3OutpJB54pIyB04DayVOG3dSiLNvsA mdH/JylVXd4wOd6dDWh2kd+dI4x9CPPJdeK/I9iTl8tA+Bllf/pAi+CYR42Z3fAlbmqA CCnNgyTdajiqGx0dfvkeS5YdKF5xcjy4BNd2CoNlp9JRhrZZfKUvzSAm4RRqo/i8pkE4 RcF2Z0BO/yedV0taIpUBzu8d7MTHJRH72/bAMeQSNpYBXLD3mrpOW4C1IZZia8D3TD7p UWuDcBy+TWe+sQ7QArrXLX12I5Pyyu0VwFdhLfDxUUqrBgQqLbklWInkPXwQ4T4vo3O2 OQqg== 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=HN1jSml8xGVKMU1qgeTlmdidtub7pA6wErpj5PAwFrg=; b=dOnRZ0gmAsRMDAGJPNUsTgyc+FKbW6t70XsShasj/hC2/dsd5aMnIejKuEjmWnV2Cv sHJV8XSPYMV8pjTm8Uc3wL8qJ79VT4nCVYhKHy+hyWbr2SgAVHiZ93mz4Ou4yN7wVX0p pLgNwH2t36aubZaayc1XfC7JbglQa9OSPdNzQyoCQwJfIqqIX9zBrVh7jzjcJpHcP9CF uVTGQ2IlMI71JVXipzB+1PjXb1uDMX7qa8SgoqPOBaO7V+d7zsu48Dte7vlq4Pz5hpYV 5rDdpDLYZor8T1zeLq/V3LB3FCAoWMmccnhuKKswam4iCPQ+SL+m/IqJIFkHMnNwHeNT CXAw== X-Gm-Message-State: AOAM533Vk1M4wmuZN82Nz77jnh0gGnuVrOdQuNd3OQAQlPweWiUx8mvH B/4UY7XWG/EY/IG7ds02+jB63VLjCwY= X-Google-Smtp-Source: ABdhPJy29aTen37dr5PjDU+WOD6BndHpJtkDJNQXj7/JVromZ5ZXqya4y31SUl+lhS+IFU1t0wMrBg== X-Received: by 2002:a05:6402:31ba:: with SMTP id dj26mr5177991edb.71.1623922314635; Thu, 17 Jun 2021 02:31:54 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:54 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 26/45] util/mmap-alloc: Support RAM_NORESERVE via MAP_NORESERVE under Linux Date: Thu, 17 Jun 2021 11:31:15 +0200 Message-Id: <20210617093134.900014-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 == 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 == 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 machine 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 c2c7fe5c47..0a54bf7be8 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 11ea8e19a6..9b171c9dbe 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2251,6 +2251,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) flags = MAP_FIXED; flags |= block->flags & RAM_SHARED ? MAP_SHARED : MAP_PRIVATE; + flags |= block->flags & RAM_NORESERVE ? MAP_NORESERVE : 0; if (block->fd >= 0) { area = 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" #define HUGETLBFS_MAGIC 0x958458f6 @@ -83,6 +84,70 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return qemu_real_host_page_size; } +#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 = qemu_map_flags & QEMU_MAP_READONLY; + const bool shared = qemu_map_flags & QEMU_MAP_SHARED; + gchar *content = 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) != qemu_real_host_page_size) { + return true; + } + + /* + * Accountable mappings in the kernel that can be affected by MAP_NORESEVE + * 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 >= 0)) { + return true; + } + + /* + * MAP_NORESERVE is globally ignored for applicable !hugetlb mappings when + * memory overcommit is set to "never". Sparse memory regions aren't really + * 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 == '\n')) { + if (tmp == 2) { + error_report("Skipping reservation of swap space is not supported:" + " \"" 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, int fd, int flags = MAP_FIXED; void *activated_ptr; - if (noreserve) { - error_report("Skipping reservation of swap space is not supported"); + if (noreserve && !map_noreserve_effective(fd, qemu_map_flags)) { return MAP_FAILED; } flags |= fd == -1 ? MAP_ANONYMOUS : 0; flags |= shared ? MAP_SHARED : MAP_PRIVATE; + flags |= noreserve ? MAP_NORESERVE : 0; if (shared && sync) { map_sync_flags = MAP_SYNC | MAP_SHARED_VALIDATE; } From patchwork Thu Jun 17 09:31:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C32FC2B9F4 for ; Thu, 17 Jun 2021 09:50:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB7366113C for ; Thu, 17 Jun 2021 09:50:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB7366113C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltof7-0001b6-TN for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:50:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNU-0002vn-51 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:00 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:43676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNQ-0006GI-Sb for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:31:59 -0400 Received: by mail-ej1-x634.google.com with SMTP id nb6so8665995ejc.10 for ; Thu, 17 Jun 2021 02:31:56 -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=lIx667c1QFQNLJ/C8Eb25dFhVVVbMNF5LrSetqUBYBzFdqu/PCKm1QV+6u0WWdT/5n PSuGKvyRo4uhfqUYoxSZdbPTWAdEWK1JN6JSc27CpvsQUnF3xSZxpMnZFYcKthWule7r PEAl2peAYhZtIrU9buZNpTDI/IW7uA9va2wTPsUxoHFCBUchYSR8qEEqUVr4SqBGnhEc /R9QzfteQcY7HAZZeGy+JMuy/HbtWlp6KTgYM9fF7NWsvjUQPhKKPjgfa6T2BEhkFhua AzzM5heWXVdybTi4gnsSuWnyggNxYzViV2GxIHW6ufR7sWSeWmnZrf5FqpwMJ58h6nLH T6JQ== 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=Pio4MmcnDb5OVtIhLGzynHVZFeC8Uf3o84ZNj/clV0CIVnlFsBGH5QHLcur7pJBb1S YMtcuOAZwi2xZ7M7gDZ1Mhp7k3OLxN10ojFNxYe+ZnTgfQQfCXSwzeqW+XbFYGAkSK8l hu+TeONn5kr8JPddDpc475zFL13W9L64ol3j6wOCLFiq3IW0ku7UjDuvZ43wMIrdEZIV G2QX1IpYTL4YzQonFpHHQv40D1Se0tFrKHmIQ1DMjdWlvbcE8Y4u/svSo0ZnG04NfN9J uNhdAblqEdeNtzxkr2SckQlFEciNyOe+HDFjabr8JUKfPn+zWRchWmAWTDo7ImGajh2e Tz7Q== X-Gm-Message-State: AOAM530L1RUbO9vTRRdVY3iDc/4iQxz80DvpVeHPWJjGfIoU1TVpZeW6 VQPSY6OkiwoYJFeKXnBktmBT5K/Mr/I= X-Google-Smtp-Source: ABdhPJwXg/gVplqJ3wqJhoJ3OaJiRf2D+rXttnN3PqMi3LX9YFvly5B/yRy+YfoucrOEpHs73ZdaOg== X-Received: by 2002:a17:906:27d3:: with SMTP id k19mr4117148ejc.368.1623922315540; Thu, 17 Jun 2021 02:31:55 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 27/45] hostmem: Wire up RAM_NORESERVE via "reserve" property Date: Thu, 17 Jun 2021 11:31:16 +0200 Message-Id: <20210617093134.900014-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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=false". 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 == 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 machine 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, Error **errp) object_get_typename(OBJECT(backend))); #else HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend); + uint32_t ram_flags; gchar *name; if (!backend->size) { @@ -51,11 +52,11 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) } name = 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 = backend->share ? RAM_SHARED : 0; + ram_flags |= backend->reserve ? 0 : RAM_NORESERVE; + ram_flags |= 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, Error **errp) name = host_memory_backend_get_name(backend); ram_flags = backend->share ? RAM_SHARED : 0; + ram_flags |= 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, Error **errp) name = host_memory_backend_get_name(backend); ram_flags = backend->share ? RAM_SHARED : 0; + ram_flags |= 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 *obj, bool value, Error *local_err = NULL; HostMemoryBackend *backend = MEMORY_BACKEND(obj); + if (!backend->reserve && value) { + error_setg(errp, "'prealloc=on' and 'reserve=off' are incompatible"); + return; + } + if (!host_memory_backend_mr_inited(backend)) { backend->prealloc = value; return; @@ -267,6 +272,7 @@ static void host_memory_backend_init(Object *obj) /* TODO: convert access to globals to compat properties */ backend->merge = machine_mem_merge(machine); backend->dump = machine_dump_guest_core(machine); + backend->reserve = true; backend->prealloc_threads = 1; } @@ -425,6 +431,30 @@ static void host_memory_backend_set_share(Object *o, bool value, Error **errp) backend->share = value; } +#ifdef CONFIG_LINUX +static bool host_memory_backend_get_reserve(Object *o, Error **errp) +{ + HostMemoryBackend *backend = MEMORY_BACKEND(o); + + return backend->reserve; +} + +static void host_memory_backend_set_reserve(Object *o, bool value, Error **errp) +{ + HostMemoryBackend *backend = 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=on' and 'reserve=off' are incompatible"); + return; + } + backend->reserve = 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 used @@ -556,6 +559,12 @@ # false generally, but true for machine # types <= 4.0) # +# Note: prealloc=true and reserve=false cannot be set at the same time. With +# reserve=true, the behavior depends on the operating system: for example, +# Linux will not reserve swap space for shared file mappings -- +# "not applicable". In contrast, reserve=false 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' } } From patchwork Thu Jun 17 09:31:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327211 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68196C2B9F4 for ; Thu, 17 Jun 2021 09:52:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 152B9613EE for ; Thu, 17 Jun 2021 09:52:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 152B9613EE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltohS-0006On-0P for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:52:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNV-0002x7-DY for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:01 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:46747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNS-0006H7-QI for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:01 -0400 Received: by mail-ed1-x534.google.com with SMTP id s15so3015854edt.13 for ; Thu, 17 Jun 2021 02:31:57 -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=A1DTawweAGq6t/PFv/dFx3APT0MuoWPBaROZTAF+k9C//g/6ntqC+fMk816A7UUaVb DqR2i4Qh3ZGlBnxPujHA6b13KxkDY9lxV6jPZgOlNUt2s9uH4pkrEe0Ooi3k08NHT2Zl I+kdd2KkCeFkU1seuILee6wrvbt5AoEQDf1XFAwjPJdHlPZbJpQFpJt7n2KJJbA2sAfq ag+b6aoaCDy5/ugCja97AkPeMQ0wYWYgF2BLoiaaWJfMjOzCTRA36iuMErBQysoz440H g3aYwRV8B0JttNTmZ08kROdVPLN3YCVXwf/5qd7BkKPNTZJD6DcHyj8onMNvl8FR3F+z 9/Qw== 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=DgZ/hiA5o66y82Kv2a9940z0n5B4umqaplDYov62/qDPrqw5BUhRUsYcuJOHWtw4Sh e0u7st9JX7Y92Gnr65kCbY84GE+UKRq0VZ5x4xC+6BixNn4QUxjgrrDNFui6dalcsSX5 6+15FlZxXg+jXSpMrbD3EV4hiEIFeFxJhEb9cZEqHkoNhfJTK8rbCD/IkpStWQsOBqua dMhHTePI+hO0xQdeAy/GOSOTHfLNvN2wRpZcXKqKut8ZqZWp/ZDxobKcFaxUnsNxkxO0 sq8cT2I2zBFd4XnQOt4l7s2Zu8j8qxr3z4sYlnhPlCmHggsmSFaTdMbkhWc7WtlXddXi USkg== X-Gm-Message-State: AOAM532p8F9K+fWeVKAjRqSecugR0ZUrNs5k41YgVrpKXaH/V9YLRtL0 PYB21ZU+Jmlv9DZMxvd5cniVwVFT1ds= X-Google-Smtp-Source: ABdhPJxbEqVglmN9Az45fYz+BGrG2FWEIt0S9KHcCq6hS/A1XSmAhC8KQJ/o2awwJqJxsQ6vlyZPOg== X-Received: by 2002:aa7:db49:: with SMTP id n9mr5131157edt.361.1623922316303; Thu, 17 Jun 2021 02:31:56 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:55 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 28/45] qmp: Clarify memory backend properties returned via query-memdev Date: Thu, 17 Jun 2021 11:31:17 +0200 Message-Id: <20210617093134.900014-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x534.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.248, 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_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Suggested-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and machine 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 # From patchwork Thu Jun 17 09:31:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE43CC2B9F4 for ; Thu, 17 Jun 2021 09:54:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F5BC61400 for ; Thu, 17 Jun 2021 09:54:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F5BC61400 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltojh-0002df-QT for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:54:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNW-0002xy-0i for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:02 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:33464) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNS-0006Hg-Rr for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:01 -0400 Received: by mail-ed1-x52c.google.com with SMTP id d7so3137018edx.0 for ; Thu, 17 Jun 2021 02:31:57 -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=ue1hY4y+EDL3w6JhNV13IGzjilZW1cqp5lXOL6RNQfpUPgh6FDLYPto5ol0BIXzNvh EfTTpR858+/TnG6fc8klQywmQIzLNoV0NETI3gok2ZMDEbL/OeapQ6n44UFi+xPJAe3W 4ZmB/H/XNZnKys8t3N6Vxe4YSETsjdTOY570kPJBQceYpM/tbfmdsfUEnCHNp2MgdbyY 3Ts5dxmLhRduVQJKzhsn08sX4Ee9LVinIP27qb8Q64uQ6xQUbGZJtJQYweHkLB6cL0Ob PDycMAtSaBwvoYG6OL5NxAo+vzy2FXTFqIMs0CI/m8B0henhHKFNiLsbGgH1ypMIbtST lDbg== 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=qmDXCHJBXkNTdxmvap645EXwzkL0ff1nyK9Q/HIwBbRsOTC2qlJXlaKG13uT1wztoZ 57oMFMR201R4tIq6galsuKriH2WyKXCPXjK6zyrQHE/yHojv4F1XQglfGiZ5AuwAj99G VDkhMcIsH1hJf1MX5oJb93JUvgqAbXsWWikLawQ7KCzhLcraVPuyjpsEgqxjcpwW2Wqb 4k0UOJ8ZV1feV3uImJ0wUEVufwE+dJHPrDhIM4EOqL/GgZyA/Kv2xBDg7NMo8inUg1z5 TJ5Sp93LRguYpAmn5pwpIaTU4g3ay3pgbVMin7Fea6f3cmjXCgTy8xOFs/aSBeuv/8B4 Z3qQ== X-Gm-Message-State: AOAM5328QrpcvDONYamUdZCvWiJEFumCwR7CE1zx8a8tStxFwLXURyW0 4Fxxh5A7L8b4wXNF72n6KoQJk0LbCi8= X-Google-Smtp-Source: ABdhPJyuxW3XdfTxpmX0aUTK2P4/UiGHTiQivd1ntNHUPf4PaLjq2GL2xu+Eib8N+43JSFA5fDL84Q== X-Received: by 2002:a05:6402:4248:: with SMTP id g8mr3896682edb.368.1623922317058; Thu, 17 Jun 2021 02:31:57 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:56 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 29/45] qmp: Include "share" property of memory backends Date: Thu, 17 Jun 2021 11:31:18 +0200 Message-Id: <20210617093134.900014-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and machine 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 = object_property_get_bool(obj, "merge", &error_abort); m->dump = object_property_get_bool(obj, "dump", &error_abort); m->prealloc = object_property_get_bool(obj, "prealloc", &error_abort); + m->share = object_property_get_bool(obj, "share", &error_abort); m->policy = object_property_get_enum(obj, "policy", "HostMemPolicy", &error_abort); host_nodes = 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' }} From patchwork Thu Jun 17 09:31:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327215 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F5B6C2B9F4 for ; Thu, 17 Jun 2021 09:53:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BE6326140F for ; Thu, 17 Jun 2021 09:53:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BE6326140F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltohq-0007jw-Uv for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:53:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNW-0002xw-1p for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:02 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:43673) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNT-0006IC-DZ for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:01 -0400 Received: by mail-ej1-x630.google.com with SMTP id nb6so8666206ejc.10 for ; Thu, 17 Jun 2021 02:31: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=+EFladb3eqe0vt+VFB7TILa1exqZV921bqMeigXL0sY=; b=QAc99yJDdTfSI8gRcaBYAjM9QSt9La9SjTvwjU5W/AvCRPWunV5Q1L08hfsN5C+1SW Y9pZpxj6XSmxUQI8pz1e7yOc2SNCG+aafbqYqBGvyAUavBA9Bh7e5wT7tHMs6ghfDxWd aveUi5tXT1oTPrKYUd7Pd97KXA2YEjtmyjIs4oE8eg26StatO15eIVygh6rU6B+iKoQc 9/yBSJwkkcn/ifnndacOWonjjj/4Oa3MR2yWAPQkVGGGlLzofWLTEllDeXw6NxxhkTcW EKpB7TvgMHvrxlGZ3rj7AvUyKBx0rEIo+tJAziJIt40kM2vttnoR3SqeP8PhFUiXGhJD d5wg== 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=QnzovNac9fStRfCzH9wwfKhNma4pzMtqXPy7TQcSYMZSeALY/SbS+/OkdhS05TqHVf ZMDAZ194vrmpSWFDmFMAYT/oRVcPHewTmhxURj/ZnuRjay7HT7ZxL9OtKkJX7VZ4u4+A U7R37L1wUJgfipXzjDCMCoIUAx0lboWvFB2nrLzWfrJKrZ9rjCbT43w5+SdNBFhxT3cS dQl/T2pKqcALS5N5WVqtYHcLYTg+zk0yuygff4g94sreqxRyJqGh6sfWgR7A3LjeVA6E N7g2DRN3ptwbXpK04DkZKnrJOhB/8MuWKxBXuA1RlGacYJjv3r2uH8vGCcfuFupS+sEl Pn7Q== X-Gm-Message-State: AOAM533lpi36e8b1k5Vh5JX8CUoeK5n7Z+MP96p5dUOPN47BBtvOX2kF M7Lc3+CjYusUUeTLI0Ow6eVkAKGuMYQ= X-Google-Smtp-Source: ABdhPJyHlLAQkIwRnQwfyLhl+PrZc6ZePkeSh3pkhPSLy/H6BofESCZ6c45rfTWdRpA9pq464PFbow== X-Received: by 2002:a17:907:1c13:: with SMTP id nc19mr4331932ejc.168.1623922317880; Thu, 17 Jun 2021 02:31:57 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:57 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 30/45] hmp: Print "share" property of memory backends with "info memdev" Date: Thu, 17 Jun 2021 11:31:19 +0200 Message-Id: <20210617093134.900014-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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_Mathieu-Daud=C3=A9?= , Markus Armbruster , "Dr . David Alan Gilbert" , Igor Mammedov , Eric Blake Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's print the property. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and machine 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); From patchwork Thu Jun 17 09:31:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFF9FC2B9F4 for ; Thu, 17 Jun 2021 10:08:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9CF8E61185 for ; Thu, 17 Jun 2021 10:08:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9CF8E61185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltowU-0003hP-UB for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:08:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNX-00030D-57 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:03 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:45597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNU-0006Ij-2t for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:02 -0400 Received: by mail-ed1-x52c.google.com with SMTP id r7so3016724edv.12 for ; Thu, 17 Jun 2021 02:31: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=Mwlb91Bq0n0L0KzBlNI9L4RP30x6/A2tSce+bkWzLWw=; b=C/53WgfxlzItSEcnj3GNqbaLfqsfYV2eLvE5bz0hrBUbpp0w7j6I592TDUF7y71QOl 7zMGZGLNxb8F1uxYBsbAGhBscEAkILiz8pUxCfreqMUHa8mPMZyfRkeU0atsguz2VurC Xn9CW6JnZ257WnnXgKpCvVXVYrB+Zklq+j5Z5EctgtfKWmoCiPmTAy8jUwGgeMy+nZE4 vQK8IlVsIA53qD9b0RWrgVnPzXf46F8pqaBTrl2oTCPG9tEv2KnpymZQ2pXRueoLOgP6 AfVE5QsJJdCVXaq99HROyLtjrErwS2sdnZmlGlXMp4zQ/XlgdXvueyaXkKicXHmLism+ MnkQ== 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=LW+v32ZzVC5HtC3G6D2YvAY5EIFJxdqAgbfdUXQZNE9dQllDvQ6krJBjtsv2K5yXXA Ou3ZBzHakbKxvnjdUvMgtqICRz5rF8G3rl3Xq6i37xyaYDypckOmRued72qhL5X/Zs8O RTeQaY35r/C9bjRxsPMpXn/VEb+yy/FdRArtwnSx1/QtS00Ws1OlM4VhMoGpnoFEJH+e /oCzh6ZPmsFSgG29hEj3MyMzJRmymN/6Fb6MO/OV1aO+uTe0B4cLAq055bsG1vWrFKzp KIoVVwaKOU2N0MJ3pdB9wBiN2WZpi75qNswBDU/mw+/x6fSu4BPXIN22hA342QxEEona H4Mg== X-Gm-Message-State: AOAM532Cjs3AA1aA5p+Pen4NDbpqPmli4mavKqWRH9IAedvQSsFjyyh7 vA19WdIwbjdNe/T+AhVazd2Mv60Bbw0= X-Google-Smtp-Source: ABdhPJzRUbG4geaLvEW/+rRaCL246mEi8XdczSCOoDMf41UHpMjvehpI60T4/IVUKxOHfwm3MFYhKQ== X-Received: by 2002:a05:6402:28a:: with SMTP id l10mr5179951edv.365.1623922318859; Thu, 17 Jun 2021 02:31:58 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:58 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 31/45] qmp: Include "reserve" property of memory backends Date: Thu, 17 Jun 2021 11:31:20 +0200 Message-Id: <20210617093134.900014-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and machine 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) static int query_memdev(Object *obj, void *opaque) { + Error *err = NULL; MemdevList **list = opaque; Memdev *m; QObject *host_nodes; @@ -173,6 +174,12 @@ static int query_memdev(Object *obj, void *opaque) m->dump = object_property_get_bool(obj, "dump", &error_abort); m->prealloc = object_property_get_bool(obj, "prealloc", &error_abort); m->share = object_property_get_bool(obj, "share", &error_abort); + m->reserve = object_property_get_bool(obj, "reserve", &err); + if (err) { + error_free_or_abort(&err); + } else { + m->has_reserve = true; + } m->policy = object_property_get_enum(obj, "policy", "HostMemPolicy", &error_abort); host_nodes = 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' }} From patchwork Thu Jun 17 09:31:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13190C48BE5 for ; Thu, 17 Jun 2021 09:48:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CBF89613BF for ; Thu, 17 Jun 2021 09:48:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBF89613BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltodB-0005sy-1S for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:48:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNa-0003AO-R3 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:07 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:36836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNV-0006KR-4V for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:06 -0400 Received: by mail-ej1-x634.google.com with SMTP id nd37so8770463ejc.3 for ; Thu, 17 Jun 2021 02:32: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=Us6ggabPs2Iu/tknvpN9PEYNzI6F+zr6OhgzB6XQ6h8=; b=nfdpN6o/siNbFJvX+C6aXLhNZJM1XMRDqjzQnFh1rCLzOqfxSTasr6WhBrZp2pn/eB PvO7LBTP7di2I0lN4FVJ7gDyNqjEnfW/5xdEhhC+I7IO9coA7q6WrVcxeDLoXFLrj2TD rvsVCXAPpAwM9dP7w/vWbh1wIbaUA5owNMyKuNfRtCZAwlGGH1Dr72FH0NFMHzGyeN8v vMSEl7ogIn2fI7a7gjc8g/s5JwG19PldrRxu0WRVM6YvF5GZ6lA0q5Wszq3uyCoYBXjT f1w2kv9/EJaa1Ork8DOvtgXll0vzpoDWzUhqQ9jVjRR1g7dCgAY4PWMfNuq730ZQPIra M1gg== 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=rJmnte0IIUrdSTtQ/7/nIJDzxGKfGw17IJQCVrAQnYws08mGjTuiynyzX4smDiuBHp kLx0ZWQ8+C/MfTkq7eDXKnthCQAiNYn3jeegDWuf56NyKUsaMHb4RSdPqkfhE9rp0TzK VEbsg1DKhKimANdYpAIocLiBivndAWyzJOhzXaSPyFbrsF82fqhWsPJ4Vm+mfhmVubVo 2OYyTg8EVXf07+X7hR3RAXaPB5D+VYEw1Ih30HzA0vq1th0UujOAr60r5OXeY6NBwGSv ThToar0sO3d8CeRuxF5s2eThxmYK17BMxlwRBwsxsAWzzGL57mLO0jI8xm3ZhoYPg7qg 85kw== X-Gm-Message-State: AOAM530LC8NlUw1KNer3udFQrj4lwq5A41PHyvdxkDcW3rC2kEawXi+U tgcXzfMnSEjxW1SEmQNhPFgedHVTDww= X-Google-Smtp-Source: ABdhPJyCdHT3qVHQK8DW0x3aBNAcck9vCyfn8nTZ7SwBypVat8z7VSo5dpDiYhADqD5AkQW2gC9tig== X-Received: by 2002:a17:907:2636:: with SMTP id aq22mr4307111ejc.48.1623922319654; Thu, 17 Jun 2021 02:31:59 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:31:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 32/45] hmp: Print "reserve" property of memory backends with "info memdev" Date: Thu, 17 Jun 2021 11:31:21 +0200 Message-Id: <20210617093134.900014-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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_Mathieu-Daud=C3=A9?= , Markus Armbruster , "Dr . David Alan Gilbert" , Igor Mammedov , Eric Blake Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: David Hildenbrand Let's print the new property. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Eduardo Habkost Reviewed-by: Markus Armbruster Acked-by: Eduardo Habkost for memory backend and machine 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); From patchwork Thu Jun 17 09:31:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B99EC2B9F4 for ; Thu, 17 Jun 2021 10:11:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E56E561185 for ; Thu, 17 Jun 2021 10:11:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E56E561185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltozt-00016H-Ut for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:11:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNX-00030F-CD for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:03 -0400 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]:37403) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNV-0006Kl-Iu for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:03 -0400 Received: by mail-ed1-x534.google.com with SMTP id b11so3068120edy.4 for ; Thu, 17 Jun 2021 02:32: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=xuAPUpX6Hhq84IfvJMkUkq8FBAkzzJSj3GQD8rT6J7c=; b=O9QWht0Qxwq5SOK0LHLj5OP4Jn7vMReMCf+l0yuMZcpHOTofOEFAZ7NKYfhWFleobL /cqZSpv486qzqeasuJ6OCvAFnXDqDdxJVoaRn7iJkhM/OQkA82QB8TkJG0bygMgTvXOz jPDJEa+5i6W85M9VHgarMEc1KZe8hZ318PopDW/nhRFCyLPb9gP4uBcGMtP1VVMPM0iF mT9QLAvMGORj27ywzK4yIcJSUM7IZhEoEdXhsPTZO9p3+tcgFsczDeuv3k7aM6Z4Y/G6 F/3NDNQUCtuug7hFwsYoBELUSIA6KSgeEEZedKAm4xXLguZ4CXFLR8pchF0ieXnMGhBt yBuA== 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=pDisY4yw3fDIFJxoB/lKJ6cYrsERGFvjl7EmBtWBhwMSzieQrVlNDr5kyISInbtr30 vo8nWJ6g+pOkhCv9CIyGZXgs3UeIRYlDwojft2xsDwNpSOdcHyrC3wLz9JzFSb5LHzKm BrJaaeEjpWWWivj6JQqmyGDm3BxfGY4RyFl8GWAJHm26jmeHl4kxjIMXUMFde9EJLFI8 AEUa5G85wd8GKYzL1QSYwME+e2UG3jNkqJAo/fxXTPtVYUvewNDQIgwmZ6LveN9pj5Ln jx/ItgM1fUKyhoUetsYxcS/c3DZs/6EyOv5s+1vTmetZRHs3v3unYa0n7VIR9zNnmMNW LaZQ== X-Gm-Message-State: AOAM532JSWxd/SeILaSErSfpqPFddX5z9mbQoL1q/gcTkz+jTr0D2MJo wkJczx/QM/ApAPFSmb86mQcnOwbQaVs= X-Google-Smtp-Source: ABdhPJyZYNcS22iDlW+KchgDwaXEiOQmgqrTnTbdJd1Q5SI4iNWFWkMm1eFK87/6WMd2A2/Aj+E5RQ== X-Received: by 2002:aa7:d388:: with SMTP id x8mr5146214edq.338.1623922320324; Thu, 17 Jun 2021 02:32:00 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 33/45] configure: map x32 to cpu_family x86_64 for meson Date: Thu, 17 Jun 2021 11:31:22 +0200 Message-Id: <20210617093134.900014-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::534; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x534.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.248, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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" = no; then i386) echo "cpu_family = 'x86'" >> $cross ;; - x86_64) + x86_64|x32) echo "cpu_family = 'x86_64'" >> $cross ;; ppc64le) From patchwork Thu Jun 17 09:31:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41733C2B9F4 for ; Thu, 17 Jun 2021 10:14:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B92EC613F1 for ; Thu, 17 Jun 2021 10:14:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B92EC613F1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltp2d-00070B-SE for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:14:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55344) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNY-000341-Sk for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:04 -0400 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]:45748) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNW-0006Kz-Cq for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:04 -0400 Received: by mail-ej1-x632.google.com with SMTP id hv20so2772785ejc.12 for ; Thu, 17 Jun 2021 02:32: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=lC/0Cp9Va8sjJCLH7XVbQgzt0OCEOfNbiDwuv03f8v8=; b=AaWj/KKJ0REhP6f7fALlmjNfNQd45tDTj+14S9PZNJ/6w+agYDl3oEDouG30A25Z1h SqIhpwNh3xZsKZ5fr4gkAzPohfOEgUaJ7rQ+pDM8uH9kkIel6Pb2dCuUXEsvv4k48xUX k1pWO384YyOpjPTFX8EvSN3Jbz0GHqpBoGXgNMYzj9GuUnQsaYiuZ0f7LTYLul4C5rct QR0yzw4Ds6NhaiX3NoueHcYWkjsa+1uWvq9ZbCFFp/R2PRhl6tSJS4xKc1YzXFq6gVAQ Ny+BxTi4DHjCPdmArXMKkstRIP2nZeBIsEwCtDT3H+5pdNqH//4wFVBxCsFC9E7hrJ8B 1qDg== 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=lC/0Cp9Va8sjJCLH7XVbQgzt0OCEOfNbiDwuv03f8v8=; b=F3Z9mImbP7O81Dw+ypeBVZ08VNzwz5K9jhrFCUb5CZJcHkKKRcsnzwAg/07ConfvQV SRxQ33EM44kUf878+PZGkFKhA+T8vaaIRGNjyVtmEP1lg50jdi8ukjXxarCQMIaAGb4w wJZz3uFZ11g14IKgaMww2qi4jXjg2czsF0QENXirvkkQ0VGfRm+nKcxCMzEsv1U4zMJP 7bJKZxujRa1cm/qFg0/u2MoxHDWsJE14WfLrTKLHips2IxbP590enVZy76MR4IR2D5uM t29fmSKFz2z8cQ11XgLW5zrWBVxNGqGDdU6wzQ83gvrbjfIBsD9DMd7D+SLAc4ZJY5K5 duMA== X-Gm-Message-State: AOAM533yUQApfhbuGzDXBvXGAA5maQjkLF49u5cfTgauNwGE9w8ZFEiG 14KbydrVhlxNMHSLy93IEq4MsmiPXyo= X-Google-Smtp-Source: ABdhPJwkC/LS/bOts1dOPtlK6G9SuWXZukoJcY2wdwFSlxNlHYRiJ/bynogR4xwec+fot4lZMO2KPg== X-Received: by 2002:a17:907:9813:: with SMTP id ji19mr4326774ejc.318.1623922320943; Thu, 17 Jun 2021 02:32:00 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 34/45] target/i386: Refactored intercept checks into cpu_svm_has_intercept Date: Thu, 17 Jun 2021 11:31:23 +0200 Message-Id: <20210617093134.900014-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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: Lara Lazier Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Lara Lazier Added cpu_svm_has_intercept to reduce duplication when checking the corresponding intercept bit outside of cpu_svm_check_intercept_param Signed-off-by: Lara Lazier Message-Id: <20210616123907.17765-2-laramglazier@gmail.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 4 + target/i386/tcg/sysemu/svm_helper.c | 133 +++++++++++++++------------- 2 files changed, 76 insertions(+), 61 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index ac3abea97c..64b4e46731 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2149,9 +2149,13 @@ static inline void cpu_svm_check_intercept_param(CPUX86State *env1, uint32_t type, uint64_t param, uintptr_t retaddr) { /* no-op */ } +static inline bool +cpu_svm_has_intercept(CPUX86State *env, uint32_t type) +{ return false; } #else void cpu_svm_check_intercept_param(CPUX86State *env1, uint32_t type, uint64_t param, uintptr_t retaddr); +bool cpu_svm_has_intercept(CPUX86State *env, uint32_t type); #endif /* apic.c */ diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/svm_helper.c index 9d671297cf..2f7606bebf 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -412,6 +412,43 @@ void helper_clgi(CPUX86State *env) env->hflags2 &= ~HF2_GIF_MASK; } +bool cpu_svm_has_intercept(CPUX86State *env, uint32_t type) +{ + switch (type) { + case SVM_EXIT_READ_CR0 ... SVM_EXIT_READ_CR0 + 8: + if (env->intercept_cr_read & (1 << (type - SVM_EXIT_READ_CR0))) { + return true; + } + break; + case SVM_EXIT_WRITE_CR0 ... SVM_EXIT_WRITE_CR0 + 8: + if (env->intercept_cr_write & (1 << (type - SVM_EXIT_WRITE_CR0))) { + return true; + } + break; + case SVM_EXIT_READ_DR0 ... SVM_EXIT_READ_DR0 + 7: + if (env->intercept_dr_read & (1 << (type - SVM_EXIT_READ_DR0))) { + return true; + } + break; + case SVM_EXIT_WRITE_DR0 ... SVM_EXIT_WRITE_DR0 + 7: + if (env->intercept_dr_write & (1 << (type - SVM_EXIT_WRITE_DR0))) { + return true; + } + break; + case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 31: + if (env->intercept_exceptions & (1 << (type - SVM_EXIT_EXCP_BASE))) { + return true; + } + break; + default: + if (env->intercept & (1ULL << (type - SVM_EXIT_INTR))) { + return true; + } + break; + } + return false; +} + void cpu_svm_check_intercept_param(CPUX86State *env, uint32_t type, uint64_t param, uintptr_t retaddr) { @@ -420,72 +457,46 @@ void cpu_svm_check_intercept_param(CPUX86State *env, uint32_t type, if (likely(!(env->hflags & HF_GUEST_MASK))) { return; } - switch (type) { - case SVM_EXIT_READ_CR0 ... SVM_EXIT_READ_CR0 + 8: - if (env->intercept_cr_read & (1 << (type - SVM_EXIT_READ_CR0))) { - cpu_vmexit(env, type, param, retaddr); - } - break; - case SVM_EXIT_WRITE_CR0 ... SVM_EXIT_WRITE_CR0 + 8: - if (env->intercept_cr_write & (1 << (type - SVM_EXIT_WRITE_CR0))) { - cpu_vmexit(env, type, param, retaddr); - } - break; - case SVM_EXIT_READ_DR0 ... SVM_EXIT_READ_DR0 + 7: - if (env->intercept_dr_read & (1 << (type - SVM_EXIT_READ_DR0))) { - cpu_vmexit(env, type, param, retaddr); - } - break; - case SVM_EXIT_WRITE_DR0 ... SVM_EXIT_WRITE_DR0 + 7: - if (env->intercept_dr_write & (1 << (type - SVM_EXIT_WRITE_DR0))) { - cpu_vmexit(env, type, param, retaddr); - } - break; - case SVM_EXIT_EXCP_BASE ... SVM_EXIT_EXCP_BASE + 31: - if (env->intercept_exceptions & (1 << (type - SVM_EXIT_EXCP_BASE))) { - cpu_vmexit(env, type, param, retaddr); - } - break; - case SVM_EXIT_MSR: - if (env->intercept & (1ULL << (SVM_EXIT_MSR - SVM_EXIT_INTR))) { - /* FIXME: this should be read in at vmrun (faster this way?) */ - uint64_t addr = x86_ldq_phys(cs, env->vm_vmcb + - offsetof(struct vmcb, - control.msrpm_base_pa)); - uint32_t t0, t1; - switch ((uint32_t)env->regs[R_ECX]) { - case 0 ... 0x1fff: - t0 = (env->regs[R_ECX] * 2) % 8; - t1 = (env->regs[R_ECX] * 2) / 8; - break; - case 0xc0000000 ... 0xc0001fff: - t0 = (8192 + env->regs[R_ECX] - 0xc0000000) * 2; - t1 = (t0 / 8); - t0 %= 8; - break; - case 0xc0010000 ... 0xc0011fff: - t0 = (16384 + env->regs[R_ECX] - 0xc0010000) * 2; - t1 = (t0 / 8); - t0 %= 8; - break; - default: - cpu_vmexit(env, type, param, retaddr); - t0 = 0; - t1 = 0; - break; - } - if (x86_ldub_phys(cs, addr + t1) & ((1 << param) << t0)) { - cpu_vmexit(env, type, param, retaddr); - } + if (!cpu_svm_has_intercept(env, type)) { + return; + } + + if (type == SVM_EXIT_MSR) { + /* FIXME: this should be read in at vmrun (faster this way?) */ + uint64_t addr = x86_ldq_phys(cs, env->vm_vmcb + + offsetof(struct vmcb, + control.msrpm_base_pa)); + uint32_t t0, t1; + + switch ((uint32_t)env->regs[R_ECX]) { + case 0 ... 0x1fff: + t0 = (env->regs[R_ECX] * 2) % 8; + t1 = (env->regs[R_ECX] * 2) / 8; + break; + case 0xc0000000 ... 0xc0001fff: + t0 = (8192 + env->regs[R_ECX] - 0xc0000000) * 2; + t1 = (t0 / 8); + t0 %= 8; + break; + case 0xc0010000 ... 0xc0011fff: + t0 = (16384 + env->regs[R_ECX] - 0xc0010000) * 2; + t1 = (t0 / 8); + t0 %= 8; + break; + default: + cpu_vmexit(env, type, param, retaddr); + t0 = 0; + t1 = 0; + break; } - break; - default: - if (env->intercept & (1ULL << (type - SVM_EXIT_INTR))) { + if (x86_ldub_phys(cs, addr + t1) & ((1 << param) << t0)) { cpu_vmexit(env, type, param, retaddr); } - break; + return; } + + cpu_vmexit(env, type, param, retaddr); } void helper_svm_check_intercept(CPUX86State *env, uint32_t type) From patchwork Thu Jun 17 09:31:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327221 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71230C2B9F4 for ; Thu, 17 Jun 2021 09:56:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3589160FF1 for ; Thu, 17 Jun 2021 09:56:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3589160FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltolc-0007bM-7l for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:56:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNY-000339-MP for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:04 -0400 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:44932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNW-0006LY-V2 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:04 -0400 Received: by mail-ej1-x62c.google.com with SMTP id gt18so8689641ejc.11 for ; Thu, 17 Jun 2021 02:32: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=zu0RUwB1p19Fagtd8xyL4/0jgFufKWq1IEEH4S5GC2c=; b=ZVTrQj9EgxNG/+/9+oq9y8opSvQAdCTmJleSeiSDMvWXhSa98q+8t8/wSRgEVWrKAC nBW0nvjwC6UH8jgqLZJm3WPQlnp0vnYvj/0MvTjpdKBS3EQsctn7GIxYtxymtoEsh25P 7QDwoF4wHBaT1nepVgw0VrnsUtfYznK2QVqIgsQmLJ1yz0cR/PKAWMxcCZtA4/s3B+i+ 4IrmhGA5j0bH8mMMkOcDkmeb8xFywyfx4+wvITUYyez0P49tZV4hNN/yxPJrX1iKPVBC Hb7fKW2PkrCZYXU6d5n6nhz7DeHBv1mcZI7B5fqoS5KjnWtjCbMlXu91FZ6M5fq91tCU xLIQ== 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=zu0RUwB1p19Fagtd8xyL4/0jgFufKWq1IEEH4S5GC2c=; b=EdXLr3ku8dGc2hARRFwUBz9fiIACZAegWicFJDRP9XfBYj0WWgC3jFYWFttLu4fdbv QMpaMFnKYp2vnBvX1h7SMjRIW4rCh+O25/6ZJvyMeplcjU8iwfOVGP4lQ+OiN5uMVeT+ gVspgxD9By9Y5FIqG2Iz9xnOpgV+tCTxAZlkmHdDd6g0njImyhNaR2Dx2/mVUctH89rH PzNFadZ/3nCYbhNrouPuKdM0jTgCh90OJUuX0TIa8M4YgGVBqllzuXq/YOGj8DhTrwFr dhuDaZkVInr5u8n+PrLJB2xrpjqF/88PKqQDLXPqtznav/djHTIKVmAawwJJI0oowLMr cxyA== X-Gm-Message-State: AOAM533b72YAZ+erGP1G8W9PYsSj0gxNzqwQQa/wKyw83sIaQvTdLVEn 2dJMfLgbkg4lO6P+5mvTOiT3NLTTMh4= X-Google-Smtp-Source: ABdhPJwHeQ9QE8QWeugkKfGIR07QYL3HZKi6YqdNL2eHQYpfr+KkJ+RxrvaOwFMTjwlEOfI5AddcpQ== X-Received: by 2002:a17:906:528b:: with SMTP id c11mr2984079ejm.156.1623922321540; Thu, 17 Jun 2021 02:32:01 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 35/45] target/i386: Added consistency checks for VMRUN intercept and ASID Date: Thu, 17 Jun 2021 11:31:24 +0200 Message-Id: <20210617093134.900014-36-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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: Lara Lazier Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Lara Lazier Zero VMRUN intercept and ASID should cause an immediate VMEXIT during the consistency checks performed by VMRUN. (AMD64 Architecture Programmer's Manual, V2, 15.5) Signed-off-by: Lara Lazier Message-Id: <20210616123907.17765-3-laramglazier@gmail.com> Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/svm_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/svm_helper.c index 2f7606bebf..902bf03fc3 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -72,6 +72,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) uint64_t nested_ctl; uint32_t event_inj; uint32_t int_ctl; + uint32_t asid; cpu_svm_check_intercept_param(env, SVM_EXIT_VMRUN, 0, GETPC()); @@ -154,9 +155,18 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) nested_ctl = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.nested_ctl)); + asid = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, + control.asid)); env->nested_pg_mode = 0; + if (!cpu_svm_has_intercept(env, SVM_EXIT_VMRUN)) { + cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); + } + if (asid == 0) { + cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); + } + if (nested_ctl & SVM_NPT_ENABLED) { env->nested_cr3 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, From patchwork Thu Jun 17 09:31:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F3ECC2B9F4 for ; Thu, 17 Jun 2021 09:55:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BEFFB61400 for ; Thu, 17 Jun 2021 09:55:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEFFB61400 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltokI-00040n-Vm for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:55:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNZ-00035S-7R for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:05 -0400 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]:46592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNX-0006M8-GR for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:04 -0400 Received: by mail-ej1-x62b.google.com with SMTP id he7so8673147ejc.13 for ; Thu, 17 Jun 2021 02:32: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=1Ui8G8tZLwk/rGM64JxEVMBWydF4cB84aHXFqaciPiU=; b=oo1klPfoD7IxWrq8Ag8HxYqUWbCHOYJQt4R4cXGHo3fUYbuNW8CvHRr0RWOyBxtL+g 0Nd2kmesSIBiHMbPh5PkdiWYDd36GVj1wx4abfHgrv64B/mZBrHeux1iY6SNbi03ecP9 1+iz7kzG+60U5c3T+cSnf10OMWB4wsK9XMRyekFb/rw0QZ4igIVcktAs7tAcfI2MMTm0 o8FWBfu3ETiOTQKO6YZn4/8CO7cUz50kejLaVNwe1dp/94uOGmmq974GbqRGQUj4YOCL PWYkHRuY3nroNaGn2DZqY8/4VzE5A6+owL4sQ6BZGWo5mQCzIJl19ZsDma3x14uco3I1 hV1A== 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=1Ui8G8tZLwk/rGM64JxEVMBWydF4cB84aHXFqaciPiU=; b=LCSvh9CcAqYfrLP/KwgcKxy8Izc+pHwRs2Dj36v8NwOYx2HQhkZ4yTKslqeSMyShcn yHgK43QaZzlBeWjq87Eu/L6EnRUxs61j58WbUxg56+KWwFHt1l2RvT/RUSV0gEjonQ6k DWPxu4UpYyTY+ddVUjpnxsYZ3TIhZLhiwgwp3BRZltPnsFT2qWLZForpvlmvSUqOMXdA 1LvuSJUK2TgwXbKYtL/CaVvcYrBQVxMfXjXZRcZ3iYAXbfSZKP7BHLdDqAcKyTxHdy0J O6zPkL42Ak+pdwh9A+VzeCPfje+yHGj8vTbsFvVzUvIiUFpx2DfQ66qCU9Gg7I2kGs+n RAow== X-Gm-Message-State: AOAM531hkW4reuek68X7+BWq5VkHpcmoGjf5pMZgc1DiaKJLvxUTTBMS IPkoX/ViE/xFV8BdgslVjC94otZfTqg= X-Google-Smtp-Source: ABdhPJzo6V3bxQqkaf8Dr8ESHuCwTT7Jbu0RUjW47rmXsuvW8kR0rZDbdOrRfY8a0j6UKAg/c77GhQ== X-Received: by 2002:a17:907:1b02:: with SMTP id mp2mr4205925ejc.196.1623922322244; Thu, 17 Jun 2021 02:32:02 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:01 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 36/45] target/i386: Added consistency checks for CR0 Date: Thu, 17 Jun 2021 11:31:25 +0200 Message-Id: <20210617093134.900014-37-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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: Lara Lazier Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Lara Lazier The combination of unset CD and set NW bit in CR0 is illegal. CR0[63:32] are also reserved and need to be zero. (AMD64 Architecture Programmer's Manual, V2, 15.5) Signed-off-by: Lara Lazier Message-Id: <20210616123907.17765-4-laramglazier@gmail.com> Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 2 ++ target/i386/svm.h | 2 ++ target/i386/tcg/sysemu/svm_helper.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 64b4e46731..1e11071d81 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -224,6 +224,8 @@ typedef enum X86Seg { #define CR0_NE_MASK (1U << 5) #define CR0_WP_MASK (1U << 16) #define CR0_AM_MASK (1U << 18) +#define CR0_NW_MASK (1U << 29) +#define CR0_CD_MASK (1U << 30) #define CR0_PG_MASK (1U << 31) #define CR4_VME_MASK (1U << 0) diff --git a/target/i386/svm.h b/target/i386/svm.h index 87965e5bc2..5098733053 100644 --- a/target/i386/svm.h +++ b/target/i386/svm.h @@ -135,6 +135,8 @@ #define SVM_NPTEXIT_GPA (1ULL << 32) #define SVM_NPTEXIT_GPT (1ULL << 33) +#define SVM_CR0_RESERVED_MASK 0xffffffff00000000U + struct QEMU_PACKED vmcb_control_area { uint16_t intercept_cr_read; uint16_t intercept_cr_write; diff --git a/target/i386/tcg/sysemu/svm_helper.c b/target/i386/tcg/sysemu/svm_helper.c index 902bf03fc3..1c2dbc1862 100644 --- a/target/i386/tcg/sysemu/svm_helper.c +++ b/target/i386/tcg/sysemu/svm_helper.c @@ -73,6 +73,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) uint32_t event_inj; uint32_t int_ctl; uint32_t asid; + uint64_t new_cr0; cpu_svm_check_intercept_param(env, SVM_EXIT_VMRUN, 0, GETPC()); @@ -192,13 +193,18 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) env->idt.limit = x86_ldl_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.idtr.limit)); + new_cr0 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr0)); + if (new_cr0 & SVM_CR0_RESERVED_MASK) { + cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); + } + if ((new_cr0 & CR0_NW_MASK) && !(new_cr0 & CR0_CD_MASK)) { + cpu_vmexit(env, SVM_EXIT_ERR, 0, GETPC()); + } /* clear exit_info_2 so we behave like the real hardware */ x86_stq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2), 0); - cpu_x86_update_cr0(env, x86_ldq_phys(cs, - env->vm_vmcb + offsetof(struct vmcb, - save.cr0))); + cpu_x86_update_cr0(env, new_cr0); cpu_x86_update_cr4(env, x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4))); From patchwork Thu Jun 17 09:31:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2935C49361 for ; Thu, 17 Jun 2021 10:17:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C96361245 for ; Thu, 17 Jun 2021 10:17:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C96361245 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltp5x-0003O4-BT for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:17:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNe-0003Fj-V5 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:10 -0400 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:45601) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNY-0006My-AZ for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:09 -0400 Received: by mail-ed1-x52f.google.com with SMTP id r7so3016939edv.12 for ; Thu, 17 Jun 2021 02:32: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=fB1DEpUXUs5bLKT6hBBiKcj8AC7+sYf8pppcVv3D4tA=; b=kpYp5u39PNQgotaElkbs2+5cTMuuOqP7FN4bFYSvgOWzlhBVK9kYosaFmtpFohZlAZ S63G8IQKU2D67OjQazV2zudlm9pecYpqNeHaUA0EbOyR4rINeeLAa3D/VTigxWNx9BQq SuBl2cMA2XPUGhpTKEdQVvxiA/NxfUTz+Oyk83w9rPuCy4P0NC5HEjU5qIu6fm3LdDlj Qb5YsAS38v7becJoJ5xjlkvJrG8hOr/ep/2VP3eChT6I/8gZMboaOaIEHVq59agE1/rN ufd2WDezapQrsDj9ZiOieRTaHSirN1KXXYOZRYwBaLjnO+k4WzUxy8cd3EnopCzVFruC cGlQ== 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=fB1DEpUXUs5bLKT6hBBiKcj8AC7+sYf8pppcVv3D4tA=; b=VRFVJeUNkyxmgUGolZAaH4ZVxUn/8AqUbNH36RngaSenddxATqumt3psj1YDRPD/oC oFz1m1lXm6EWYl6fJIEFII5+0Qpbh51BIpy33mWbmp+gTdFo3Aoab6P6/Plvxqxhm2YT V20kro+DcNI84z486HUw1MEhBg6fc0OCe1z6J7dLw6rG0s41zrGPxmS/rzZAbjwY6oTN bEHpic/6MSSjZvxDy5Bf+jzCnLbo2UDRb8ertmJv4Poe3cx7IbgjGEhxofIwRvOx2ZMO zhRzwGrRoJhC565jwVIOZeyd0nxlSwGzxK2QLRUEh0OD+w2iq3QGSk2GfKXIIxFFOUpL 0s9A== X-Gm-Message-State: AOAM530U4tpXCZGQiKeMI1ydt3J7/LY4I9Y4UwacOATF8SuhuuO3pPQm vXJ7ugciYcdZf3jJ1wFAZu/aP7JlWBw= X-Google-Smtp-Source: ABdhPJy23m9sxOi91979Hyuguf/FVpesrQ+hWwwCnYo5/ByIHLzx4Mp7ZT1LSref5685KdDN92+U9A== X-Received: by 2002:a50:ccd8:: with SMTP id b24mr1943333edj.386.1623922322859; Thu, 17 Jun 2021 02:32:02 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 37/45] target/i386: Added Intercept CR0 writes check Date: Thu, 17 Jun 2021 11:31:26 +0200 Message-Id: <20210617093134.900014-38-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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: Lara Lazier Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Lara Lazier When the selective CR0 write intercept is set, all writes to bits in CR0 other than CR0.TS or CR0.MP cause a VMEXIT. Signed-off-by: Lara Lazier Message-Id: <20210616123907.17765-5-laramglazier@gmail.com> Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/misc_helper.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/i386/tcg/sysemu/misc_helper.c b/target/i386/tcg/sysemu/misc_helper.c index 0cef2f1a4c..db0d8a9d79 100644 --- a/target/i386/tcg/sysemu/misc_helper.c +++ b/target/i386/tcg/sysemu/misc_helper.c @@ -84,6 +84,15 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0) { switch (reg) { case 0: + /* + * If we reach this point, the CR0 write intercept is disabled. + * But we could still exit if the hypervisor has requested the selective + * intercept for bits other than TS and MP + */ + if (cpu_svm_has_intercept(env, SVM_EXIT_CR0_SEL_WRITE) && + ((env->cr[0] ^ t0) & ~(CR0_TS_MASK | CR0_MP_MASK))) { + cpu_vmexit(env, SVM_EXIT_CR0_SEL_WRITE, 0, GETPC()); + } cpu_x86_update_cr0(env, t0); break; case 3: From patchwork Thu Jun 17 09:31:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DC92C2B9F4 for ; Thu, 17 Jun 2021 09:58:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA91761185 for ; Thu, 17 Jun 2021 09:58:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA91761185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltomh-0000ps-Oe for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:58:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNa-0003AL-Qf for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:07 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:37400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNY-0006Nr-S7 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:06 -0400 Received: by mail-ed1-x530.google.com with SMTP id b11so3068346edy.4 for ; Thu, 17 Jun 2021 02:32: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=gjriBpMgI0q1a3xgarAd+lYGNkwH88TJaY1pIobYkWM=; b=p+ZYzkJ8hnrgYk5Zx6Ki+jpROUbXdkEnteGU23Y3QTyjOc51nXwmKQFmUbqc5sSli6 c9kdJx6vsF6BQRe4JxJIGS0RP3uNjTH8KXMJYjYKib2jySgrjf8FEzzR9R9UuD2LYsxF x1HXvrZb7TymzGDnbqkBbYils5R/nfSJ4W/zEa8lUXGydHdMIXFTjFpxdfxbW8IMnk1i 4ufhS9zPGmaz5fCfOeh1BvJINV3Erxp9J2JMV/VbfoLwKNTx+eB4vMR32mDIkby9zKTc HJRDLJYNskSImrRbMEu+JcQXf71dSIZqDJLIurKe6c11LqyvzuzHBE6t3Ls4g9lgGIaw bMKA== 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=gjriBpMgI0q1a3xgarAd+lYGNkwH88TJaY1pIobYkWM=; b=F11EjkezlUjnqPWZUvazz5CyQIqDRyI61pScwiB6AGSAfAxq65S0+EQQYXLYNYTqlm CNMTFbeAXkYZ4WLU2vdneeIqZa2rjr+BeZOsy950sddETybHbLWQLazJdu42fzF93bg6 62M8tIvnL06U0ykhesMcbpYawhFjgtGEpqYsygVt15D+UzsSiHoiKqUE3+6ZoXdKs+mf iML5SJ27OKtNZUJlU7vI2qHtR+jANx0DqJXJmzSjpi1m5TdSMgIWWJkLRzPrHLQBZFm9 U15zu3cvpMvAPHMH36dW9E5JWT3MZyo6Bq0mU5C/E6uNouQV+LIIBTX/21Tu2TOMIM4J 5MlA== X-Gm-Message-State: AOAM532Wme00Xft8U3SubE082MY7zfY4Jo1eMUZ6kb78hrMaWQIUiWok HbNTCDTD+BTOOrqsKOtNkgMlgNG7p/U= X-Google-Smtp-Source: ABdhPJzlDGzFadndfMQRN0GwYJrn3ZoGDbK0HLhLI8fqjSYRhFG1L0Kj8HKTYZdJ6bUpN+Qs7vP5iw== X-Received: by 2002:aa7:cc19:: with SMTP id q25mr5235184edt.56.1623922323547; Thu, 17 Jun 2021 02:32:03 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 38/45] configure: Use -std=gnu11 Date: Thu, 17 Jun 2021 11:31:27 +0200 Message-Id: <20210617093134.900014-39-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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?Alex_Benn=C3=A9e?= , Thomas Huth , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Now that the minimum gcc version is 7.5, we can use C11. This will allow lots of cleanups to the code, currently hidden behind macros in include/qemu/compiler.h. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Thomas Huth Message-Id: <20210614233143.1221879-2-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- configure | 4 ++-- meson.build | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 4478f3889a..ebc016111a 100755 --- a/configure +++ b/configure @@ -159,7 +159,7 @@ update_cxxflags() { # options which some versions of GCC's C++ compiler complain about # because they only make sense for C programs. QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS" - CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu99/-std=gnu++11/) + CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/) for arg in $QEMU_CFLAGS; do case $arg in -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\ @@ -538,7 +538,7 @@ QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS" QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS" # Flags that are needed during configure but later taken care of by Meson -CONFIGURE_CFLAGS="-std=gnu99 -Wall" +CONFIGURE_CFLAGS="-std=gnu11 -Wall" CONFIGURE_LDFLAGS= diff --git a/meson.build b/meson.build index a2311eda6e..d8a92666fb 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('qemu', ['c'], meson_version: '>=0.55.0', - default_options: ['warning_level=1', 'c_std=gnu99', 'cpp_std=gnu++11', 'b_colorout=auto'] + + default_options: ['warning_level=1', 'c_std=gnu11', 'cpp_std=gnu++11', 'b_colorout=auto'] + (meson.version().version_compare('>=0.56.0') ? [ 'b_staticpic=false' ] : []), version: run_command('head', meson.source_root() / 'VERSION').stdout().strip()) From patchwork Thu Jun 17 09:31:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BD54C2B9F4 for ; Thu, 17 Jun 2021 09:59:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6AC5161185 for ; Thu, 17 Jun 2021 09:59:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6AC5161185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltooG-0004r6-Hw for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:59:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNb-0003Ay-9s for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:07 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:35406) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNZ-0006Ob-GC for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:06 -0400 Received: by mail-ed1-x530.google.com with SMTP id df12so568673edb.2 for ; Thu, 17 Jun 2021 02:32:05 -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=wBL1fkSPUK79ExHBJomnE+g34nGDCbvEomLmRGvHvzU=; b=pmGtN9CeLs+MuzNQms8ZXkK+91w2TTEQ5onBoJ0ygQH9cpDwM9cACJElzoYlqUp2kU sZ1LHj9ZoWvY3ICNWJSybT20uAEo7f/KXluK/tbnCVvPl+iNIY2MxqJBxb2YTOX+V4ZR +XWQvi5EzBqtEG3OvXxxrZ56cTU+46Kse+4K30BPJWTa9DdP8iHjE3/sR/ItsIfjHtN9 dP83FBEcZcw2T8WO/7Jgj/cP2uUalXr5ofbenWBo1v4AtjoB+vCjmBDabZ3LVu6tl+Ew 0e0jhAfHZvD3T16UkOjLymc1EgEYwPKoteKp2BCNt7DVtpn2ERvaAS4A7tQNxhbbBPmb c6Hw== 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=wBL1fkSPUK79ExHBJomnE+g34nGDCbvEomLmRGvHvzU=; b=lpM1wnpW/eAFpBpH8mW1ZZZb4tMxBOURux3SvLZb/66XY9jaMRRLcXoDgzfBJ/D6JZ YjGPtbDvMT9WGj8/4K3yDcCZwvNk5/M8+K3oKVWpT7tZzKQlMMZLMgHu0wynm25ilrwC 32A1idqf8/ksQFXV5l5oKHBw8xlw59NR5N0kPWC3tYxPUHasovaUqzBvjyV4NxNPsBwv VXY21jv/HQSmymnhBYhDqyfLLUUFFZR8pWNT23JBMW6s84EHDYE3wTIuffJDM/KZ6dd3 OVjUZWzeIOjtx7Pn/rVHnwBx6ErOun33cxnpWcUq+1SgFWX2anWFIQFyitbBu1eIy7lw 4FtA== X-Gm-Message-State: AOAM533rTb/j7/cLxQIxuD0Tg/wkMgGN8HqEqQ7sWJwhlfP+qHsWPXOI w9UhZFESdib4er2ULwO/i9ZmRl78mUw= X-Google-Smtp-Source: ABdhPJzJ2vyY2ms50HEE0D9kn/lKfo6O9gILkanR0LlHGzA+8M19aSrda7uK3ELh3Cv3scnJ0ZjAFg== X-Received: by 2002:a05:6402:5244:: with SMTP id t4mr5315829edd.254.1623922324203; Thu, 17 Jun 2021 02:32:04 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:03 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 39/45] softfloat: Use _Generic instead of QEMU_GENERIC Date: Thu, 17 Jun 2021 11:31:28 +0200 Message-Id: <20210617093134.900014-40-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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?Alex_Benn=C3=A9e?= , Thomas Huth , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Thomas Huth Message-Id: <20210614233143.1221879-3-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- fpu/softfloat.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 4d0160fe9c..6e769f990c 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -686,11 +686,13 @@ static float128 float128_pack_raw(const FloatParts128 *p) #include "softfloat-specialize.c.inc" #define PARTS_GENERIC_64_128(NAME, P) \ - QEMU_GENERIC(P, (FloatParts128 *, parts128_##NAME), parts64_##NAME) + _Generic((P), FloatParts64 *: parts64_##NAME, \ + FloatParts128 *: parts128_##NAME) #define PARTS_GENERIC_64_128_256(NAME, P) \ - QEMU_GENERIC(P, (FloatParts256 *, parts256_##NAME), \ - (FloatParts128 *, parts128_##NAME), parts64_##NAME) + _Generic((P), FloatParts64 *: parts64_##NAME, \ + FloatParts128 *: parts128_##NAME, \ + FloatParts256 *: parts256_##NAME) #define parts_default_nan(P, S) PARTS_GENERIC_64_128(default_nan, P)(P, S) #define parts_silence_nan(P, S) PARTS_GENERIC_64_128(silence_nan, P)(P, S) @@ -892,11 +894,13 @@ static void parts128_log2(FloatParts128 *a, float_status *s, const FloatFmt *f); */ #define FRAC_GENERIC_64_128(NAME, P) \ - QEMU_GENERIC(P, (FloatParts128 *, frac128_##NAME), frac64_##NAME) + _Generic((P), FloatParts64 *: frac64_##NAME, \ + FloatParts128 *: frac128_##NAME) #define FRAC_GENERIC_64_128_256(NAME, P) \ - QEMU_GENERIC(P, (FloatParts256 *, frac256_##NAME), \ - (FloatParts128 *, frac128_##NAME), frac64_##NAME) + _Generic((P), FloatParts64 *: frac64_##NAME, \ + FloatParts128 *: frac128_##NAME, \ + FloatParts256 *: frac256_##NAME) static bool frac64_add(FloatParts64 *r, FloatParts64 *a, FloatParts64 *b) { From patchwork Thu Jun 17 09:31:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BF6AC2B9F4 for ; Thu, 17 Jun 2021 10:03:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37E1A61185 for ; Thu, 17 Jun 2021 10:03:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37E1A61185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltorV-0002HC-CZ for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:03:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNb-0003CD-MX for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:07 -0400 Received: from mail-ed1-x52a.google.com ([2a00:1450:4864:20::52a]:42512) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNa-0006P0-24 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:07 -0400 Received: by mail-ed1-x52a.google.com with SMTP id i13so3039290edb.9 for ; Thu, 17 Jun 2021 02:32:05 -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=JC6jDpOW9MIOT5eEE0twrZyJmHuq2x22gNqBjt+axpw=; b=qLtioOA0pDI271G52lPzyTkwUH5MTzpzevMcTlWT2+KT2rfJ13gcHMI/9cWdJ5puau 3QoHPuULjmHjQPR2JE1FAmK9Dj24kCHEiU8hrHuibfVxIFMKYO4WiJpgCsiMEdYE3V1F QWXfGNWVCaaa4sQkjYtdSEk+l1aTqLAlyuXZyQwkmhlPJuenk0FGVtV8SJgYTQ1rYII1 +Av4cSZXH+b/zAHpUp/+gkmYmp3xH07tF8HYAeLrzzbg1YUZBSyFPflSph8XRx1YobRs 70WHVcXTKgixrV/nkCyiSTg0BW5YZAs76BafC3j5MC8f/qAbvRQadqg1ecNkDlm5/cZT bzmw== 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=JC6jDpOW9MIOT5eEE0twrZyJmHuq2x22gNqBjt+axpw=; b=B8ZIIFQbJS6hwzKK5JXeFTrSSU208CEYWn6x67xHCnemHwTVbK1Rn/0gt4cm3szl7E b0tqFQeQjl8ETjGbiprsEBmdW/rd0YrpQVt7nQzPuAYsr79beoz3HQVXz9Gt2pNKTj/J BB+hshKcV+E76XxExHBeHlejjSJr9MX7aCZUCWdV0AVgUljeIpBAkJ7nwX1gRLqRUpx/ ujx2p3aBU82P+fCIPhdn5LbUGqWy5r3FG2dfVKgGIQDQWua3tQvlKv1QZujEoEUDPU29 bht+hj1wr8O5OmrKplhrRpvHKG6z6Se+TJ+0Fap9laFVqZXDn1LJFer+E3GgBkvANAEP ETng== X-Gm-Message-State: AOAM530sY8xt8fWUR5vbsfRbrqm8cF4x57h/PPx/SouaaIYLNCVZLTae QpnwCt7sTf15mo3pTuHMDp4HnFwXjgA= X-Google-Smtp-Source: ABdhPJzf1TKbDSYAj+DvmqyloTIjnYWEqWL7YdfZ34G702XMbRhB/eGiADtzTP6Q9uBnj3JxLci7wA== X-Received: by 2002:a05:6402:2706:: with SMTP id y6mr2205053edd.330.1623922324882; Thu, 17 Jun 2021 02:32:04 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:04 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 40/45] util: Use real functions for thread-posix QemuRecMutex Date: Thu, 17 Jun 2021 11:31:29 +0200 Message-Id: <20210617093134.900014-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::52a; envelope-from=paolo.bonzini@gmail.com; helo=mail-ed1-x52a.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.248, 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?Alex_Benn=C3=A9e?= , Thomas Huth , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Move the declarations from thread-win32.h into thread.h and remove the macro redirection from thread-posix.h. This will be required by following cleanups. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Thomas Huth Message-Id: <20210614233143.1221879-4-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- include/qemu/thread-posix.h | 4 ---- include/qemu/thread-win32.h | 6 ------ include/qemu/thread.h | 9 ++++++--- util/qemu-thread-posix.c | 20 ++++++++++++++++++++ 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index c903525062..cf8bc90468 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -5,10 +5,6 @@ #include typedef QemuMutex QemuRecMutex; -#define qemu_rec_mutex_destroy qemu_mutex_destroy -#define qemu_rec_mutex_lock_impl qemu_mutex_lock_impl -#define qemu_rec_mutex_trylock_impl qemu_mutex_trylock_impl -#define qemu_rec_mutex_unlock qemu_mutex_unlock struct QemuMutex { pthread_mutex_t lock; diff --git a/include/qemu/thread-win32.h b/include/qemu/thread-win32.h index d0a1a9597e..d95af4498f 100644 --- a/include/qemu/thread-win32.h +++ b/include/qemu/thread-win32.h @@ -18,12 +18,6 @@ struct QemuRecMutex { bool initialized; }; -void qemu_rec_mutex_destroy(QemuRecMutex *mutex); -void qemu_rec_mutex_lock_impl(QemuRecMutex *mutex, const char *file, int line); -int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, - int line); -void qemu_rec_mutex_unlock(QemuRecMutex *mutex); - struct QemuCond { CONDITION_VARIABLE var; bool initialized; diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 5435763184..2c0d85f3bc 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -28,6 +28,12 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, const char *file, const int line); void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, const int line); void qemu_mutex_unlock_impl(QemuMutex *mutex, const char *file, const int line); +void qemu_rec_mutex_init(QemuRecMutex *mutex); +void qemu_rec_mutex_destroy(QemuRecMutex *mutex); +void qemu_rec_mutex_lock_impl(QemuRecMutex *mutex, const char *file, int line); +int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, int line); +void qemu_rec_mutex_unlock(QemuRecMutex *mutex); + typedef void (*QemuMutexLockFunc)(QemuMutex *m, const char *f, int l); typedef int (*QemuMutexTrylockFunc)(QemuMutex *m, const char *f, int l); typedef void (*QemuRecMutexLockFunc)(QemuRecMutex *m, const char *f, int l); @@ -129,9 +135,6 @@ static inline int (qemu_rec_mutex_trylock)(QemuRecMutex *mutex) return qemu_rec_mutex_trylock(mutex); } -/* Prototypes for other functions are in thread-posix.h/thread-win32.h. */ -void qemu_rec_mutex_init(QemuRecMutex *mutex); - void qemu_cond_init(QemuCond *cond); void qemu_cond_destroy(QemuCond *cond); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index dcff5e7c5d..8e2b6653f5 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -124,6 +124,26 @@ void qemu_rec_mutex_init(QemuRecMutex *mutex) mutex->initialized = true; } +void qemu_rec_mutex_destroy(QemuRecMutex *mutex) +{ + qemu_mutex_destroy(mutex); +} + +void qemu_rec_mutex_lock_impl(QemuRecMutex *mutex, const char *file, int line) +{ + qemu_mutex_lock_impl(mutex, file, line); +} + +int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, int line) +{ + return qemu_mutex_trylock_impl(mutex, file, line); +} + +void qemu_rec_mutex_unlock(QemuRecMutex *mutex) +{ + qemu_mutex_unlock(mutex); +} + void qemu_cond_init(QemuCond *cond) { int err; From patchwork Thu Jun 17 09:31:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 941B9C2B9F4 for ; Thu, 17 Jun 2021 10:16:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2190861185 for ; Thu, 17 Jun 2021 10:16:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2190861185 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56514 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltp4c-0001cR-0A for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:16:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNc-0003Dx-IC for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:08 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]:37396) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNa-0006Pa-SX for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:08 -0400 Received: by mail-ed1-x52b.google.com with SMTP id b11so3068468edy.4 for ; Thu, 17 Jun 2021 02:32:06 -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=Y56nUWEYX1Cg83SkEbZbhuCRN/h8u6OlN8CrNOsG72o=; b=M8dceNHHdIEU8fVkaSXqQyVKz/ejMeXciudm5NGt71cDEcd3RKPgahB+nnDDxQ/bdi 1NwZdWINQGN7uwzhja22qCJWZu/Rv3qos9zTZzbeljeahkbYiwNpNO1Q49H5Jo0HvcJZ soaoKsiLAUp+sqae9raoCkjiCRFSTA226D+crEHdFgvijhTKl2eqwThVAiL6hfBQ0Tu6 MGtGZ/iC4lwInKI2Com9u6LVVzbNxYLG5M7hUl5unHSVS+GFvY//IgCvyqy6GcVlIAmp KXy7IBHrxwpfhcJ3gDEDaDtLQn1LvPVGyYuLe7nxa4uH3UvaehLTcdTGiIvvoxkdp2zI RFXw== 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=Y56nUWEYX1Cg83SkEbZbhuCRN/h8u6OlN8CrNOsG72o=; b=WMspPYx+A5ifoipTig2C1OlZesR/OOp1Qa+h9v/MHL7kBeqK75C81mBsXiE/OL1WdD HBUn7i6u2B/IwbJ+0QmL3z9wSGqG2QOBjUrsRYU0hW0jT5Vp55cmAis8q3oUe+WdqqP6 l3eBmGO8rtdzG1oYx/KY7w5Hlm5PhAGuZutt9xYGLgDWXR7BlF2u++Wsn1uAh6Z3llpb iKKJ+iF/2DWHgEjsylOjAvkAQXvHmDe7yiwM6mLr9BEzjMf/6OTNN3pyiSBmNsaOvwNv ebvegZJmSz7bRJk/i28eFWXqc4dSSqFJ65xeR4TlGzGXkj627yjFD0EEX+DzkXgFVRL3 K9lQ== X-Gm-Message-State: AOAM530DofGsDtl9xka5F2RHxRehsRO7TKX7K1HymBfhvpHNBR41HX3+ qd3GoHebT4vcqbk+uZf33GC6laKupzI= X-Google-Smtp-Source: ABdhPJwpa0pPg9VSiqdaQ4IFb0Uic1JUoNptwBhcu2TryPaqXCOPAi88KmO5jxM8eQVySHBlmVKX5Q== X-Received: by 2002:a05:6402:35cc:: with SMTP id z12mr5298937edc.45.1623922325530; Thu, 17 Jun 2021 02:32:05 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 41/45] util: Pass file+line to qemu_rec_mutex_unlock_impl Date: Thu, 17 Jun 2021 11:31:30 +0200 Message-Id: <20210617093134.900014-42-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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?Alex_Benn=C3=A9e?= , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Create macros for file+line expansion in qemu_rec_mutex_unlock like we have for qemu_mutex_unlock. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20210614233143.1221879-5-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- include/qemu/thread.h | 10 +++++++++- util/qemu-thread-posix.c | 4 ++-- util/qemu-thread-win32.c | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 2c0d85f3bc..460568d67d 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -32,7 +32,7 @@ void qemu_rec_mutex_init(QemuRecMutex *mutex); void qemu_rec_mutex_destroy(QemuRecMutex *mutex); void qemu_rec_mutex_lock_impl(QemuRecMutex *mutex, const char *file, int line); int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, int line); -void qemu_rec_mutex_unlock(QemuRecMutex *mutex); +void qemu_rec_mutex_unlock_impl(QemuRecMutex *mutex, const char *file, int line); typedef void (*QemuMutexLockFunc)(QemuMutex *m, const char *f, int l); typedef int (*QemuMutexTrylockFunc)(QemuMutex *m, const char *f, int l); @@ -110,6 +110,9 @@ extern QemuCondTimedWaitFunc qemu_cond_timedwait_func; #define qemu_mutex_unlock(mutex) \ qemu_mutex_unlock_impl(mutex, __FILE__, __LINE__) +#define qemu_rec_mutex_unlock(mutex) \ + qemu_rec_mutex_unlock_impl(mutex, __FILE__, __LINE__) + static inline void (qemu_mutex_lock)(QemuMutex *mutex) { qemu_mutex_lock(mutex); @@ -135,6 +138,11 @@ static inline int (qemu_rec_mutex_trylock)(QemuRecMutex *mutex) return qemu_rec_mutex_trylock(mutex); } +static inline void (qemu_rec_mutex_unlock)(QemuRecMutex *mutex) +{ + qemu_rec_mutex_unlock(mutex); +} + void qemu_cond_init(QemuCond *cond); void qemu_cond_destroy(QemuCond *cond); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 8e2b6653f5..d990826ed8 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -139,9 +139,9 @@ int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, int line) return qemu_mutex_trylock_impl(mutex, file, line); } -void qemu_rec_mutex_unlock(QemuRecMutex *mutex) +void qemu_rec_mutex_unlock_impl(QemuRecMutex *mutex, const char *file, int line) { - qemu_mutex_unlock(mutex); + qemu_mutex_unlock_impl(mutex, file, line); } void qemu_cond_init(QemuCond *cond) diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index cb5aa2018c..52eb19f351 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -105,7 +105,7 @@ int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, int line) return !TryEnterCriticalSection(&mutex->lock); } -void qemu_rec_mutex_unlock(QemuRecMutex *mutex) +void qemu_rec_mutex_unlock_impl(QemuRecMutex *mutex, const char *file, int line) { assert(mutex->initialized); LeaveCriticalSection(&mutex->lock); From patchwork Thu Jun 17 09:31:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFDC9C2B9F4 for ; Thu, 17 Jun 2021 09:50:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7687B613BF for ; Thu, 17 Jun 2021 09:50:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7687B613BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltofU-0002WR-LR for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:50:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNd-0003EJ-3w for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:10 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:40605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNb-0006Q3-Ec for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:08 -0400 Received: by mail-ej1-x630.google.com with SMTP id my49so8697533ejc.7 for ; Thu, 17 Jun 2021 02:32:07 -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=JNJr/AA+BlXc1zPZLzRJ8Y7azIDxrXiDPF6G2uWQRjc=; b=hEkuoq0tnrqsRmZtsbEJNE6inmjPOnQS34lWm2RdrqkF9aBR9NUjW/aDSmhPhitmkW jXttsQa0lUVesQIuhDoQzLdId64d0Z3Evexpzh7KKGp9Dsg6s9uqv4UHNQzVwTSamVFP DpvEvzUQkSWHa98fZxxIlRRZOK+MwKs6k5gqzv9QlPltrayKTWN82gUscBcorll8Ck9N ukWx4lMtHZ9PdyiPUjFLkf2OWrm4L5zTa13xWK3T1XHEtCpfcsW3s0XUiL1Jn8CLD1/x vViEP2jYwkP6eHQzv6vbYEe5nYW2ia/cDXY55+qvQnRuHMye1o0D9fAb5hcgjRT4zX3q VDMA== 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=JNJr/AA+BlXc1zPZLzRJ8Y7azIDxrXiDPF6G2uWQRjc=; b=fK5ZvBIy7QCy5En+/O9SxxZNdxFXpe8iIgCOG50sOXrpJnStk0zaBMuiWuzk6rdQvA Qr8WfUXOYe4xpQ7NQEwtoNSvfWcF74Q5fy5AttcFNy3Iyv0HAYdJiMb4N0bcMu0Bv1cy 7JXBpizDTwiTTsk6USvhLF9Sh76uXVHCwmt3bZ+LRA5IW8YqDpA4n7zA6M2UFnoDa998 +sXB3OwACjGNkB8EsvRqLgD8nBXuimtxMYL8rslm7Pv7zJ+Txyf0l7m5E6WWncS94A1S dYRSfeHbibYdYHumCV12IORf7enBQiFEHUC7bSkCRildTwUeqZuqKq+MrB8xK4PSjtz0 LTFg== X-Gm-Message-State: AOAM532KSBMUOHRlEgte5orFyrNJW1EWApbRj/p2Jb0FuGkwp3St9iTD bMwtLvdQkJSw9hVIxetKvZdP7W+Pmp8= X-Google-Smtp-Source: ABdhPJw2dIbB3J71bfR6dDDM6kgu2vqEHyCyOxKLR8BAp1pCeMJT/uYV4wEmBpjlIQYmoHXyu9DMng== X-Received: by 2002:a17:907:1c9e:: with SMTP id nb30mr4278702ejc.0.1623922326208; Thu, 17 Jun 2021 02:32:06 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:05 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 42/45] util: Use unique type for QemuRecMutex in thread-posix.h Date: Thu, 17 Jun 2021 11:31:31 +0200 Message-Id: <20210617093134.900014-43-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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?Alex_Benn=C3=A9e?= , Thomas Huth , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We will shortly convert lockable.h to _Generic, and we cannot have two compatible types in the same expansion. Wrap QemuMutex in a struct, and unwrap in qemu-thread-posix.c. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Thomas Huth Message-Id: <20210614233143.1221879-6-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- include/qemu/thread-posix.h | 10 ++++++++-- util/qemu-thread-posix.c | 12 ++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index cf8bc90468..b792e6ef37 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -4,8 +4,6 @@ #include #include -typedef QemuMutex QemuRecMutex; - struct QemuMutex { pthread_mutex_t lock; #ifdef CONFIG_DEBUG_MUTEX @@ -15,6 +13,14 @@ struct QemuMutex { bool initialized; }; +/* + * QemuRecMutex cannot be a typedef of QemuMutex lest we have two + * compatible cases in _Generic. See qemu/lockable.h. + */ +typedef struct QemuRecMutex { + QemuMutex m; +} QemuRecMutex; + struct QemuCond { pthread_cond_t cond; bool initialized; diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index d990826ed8..fd9d714038 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -116,32 +116,32 @@ void qemu_rec_mutex_init(QemuRecMutex *mutex) pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - err = pthread_mutex_init(&mutex->lock, &attr); + err = pthread_mutex_init(&mutex->m.lock, &attr); pthread_mutexattr_destroy(&attr); if (err) { error_exit(err, __func__); } - mutex->initialized = true; + mutex->m.initialized = true; } void qemu_rec_mutex_destroy(QemuRecMutex *mutex) { - qemu_mutex_destroy(mutex); + qemu_mutex_destroy(&mutex->m); } void qemu_rec_mutex_lock_impl(QemuRecMutex *mutex, const char *file, int line) { - qemu_mutex_lock_impl(mutex, file, line); + qemu_mutex_lock_impl(&mutex->m, file, line); } int qemu_rec_mutex_trylock_impl(QemuRecMutex *mutex, const char *file, int line) { - return qemu_mutex_trylock_impl(mutex, file, line); + return qemu_mutex_trylock_impl(&mutex->m, file, line); } void qemu_rec_mutex_unlock_impl(QemuRecMutex *mutex, const char *file, int line) { - qemu_mutex_unlock_impl(mutex, file, line); + qemu_mutex_unlock_impl(&mutex->m, file, line); } void qemu_cond_init(QemuCond *cond) From patchwork Thu Jun 17 09:31:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9619C2B9F4 for ; Thu, 17 Jun 2021 10:06:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6A9EF6109D for ; Thu, 17 Jun 2021 10:06:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A9EF6109D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltoul-00085X-Jg for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:06:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNf-0003Fr-00 for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:11 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:33425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNc-0006RS-8e for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:09 -0400 Received: by mail-ej1-x634.google.com with SMTP id g20so8826890ejt.0 for ; Thu, 17 Jun 2021 02:32:07 -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=xNQYL3e/qOseQC5VO9f224envW8cvgsN2R0SpAwLVbk=; b=OjAj1GuOTJ6Yp1FgleT7b4Jeq69OVbocUmu4HzW4sVfhNszU4p4KT1R+86QaiYMclw T9qUe4nStfUjMwExmPrgc59Gy2gw+iSI9gVhdHVKkpBCPSX26wrnmheYCH8836DUSQTZ hnEfwA8jD0RuV5yS1C9XLeGa0dCGUWSQ9GkgG5uqVO32AT1su4Xzgu74IXjYH/QJD7jr Y6LIxLMHIJWFywxv030oyX86t06szGbtTpvSXf/DFSKlFzlD+crjLDcpNSeyj1JjVKap UmIg7yvxSFFDZ/tvUclHAI67omwywswlGP8PSmQgXFI3zdfxDcGKN/Rc0CXkL60DsiaU Ka6w== 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=xNQYL3e/qOseQC5VO9f224envW8cvgsN2R0SpAwLVbk=; b=tg776WiErbHjiuQVghWcT9xqrhsilYyIoiOPpaDUhzoeVzdqJVZeqV6m7KHPNTZV7C YyIgmSKNGRa0gDZ6CHVTDnmcAfMimnH2lUzBaLvY33HhvzZh13iZqMtSjwixuzRbD3sQ YxgTLPu6ngDlDz9U1N0rzCtZ4/l7j7jm2BQ14676mmWMoYq1uO9mnzxoqX5NcvZfd9N/ JFtRHeNXK/5JstgxuTSA5d1wOebV/e/zKEj13Gx88XSn6AM/jAQwackMZ8G8DmONJpRz fedNYY2i7yCOxugRdA9/PH9S6NEKD56rQV6oMVtosgW+0vz6tMAXdvGrCvuWihSoDic/ baBw== X-Gm-Message-State: AOAM531PqCZlaDjBqi37vdxCg5wQueNJ2wsSiS6R/V/Bs1DdsnZSLeeU Cs7/YkV7kvWOrJMo9Lb17HoOqy6Q/GE= X-Google-Smtp-Source: ABdhPJx3bIFzZ9Ts20mZSRraK73qFOIAsldEmyyXUav8SkceSqwgzHkj5ygfmzQ0J9eBTt/dtknv1A== X-Received: by 2002:a17:906:eb17:: with SMTP id mb23mr4269825ejb.239.1623922326921; Thu, 17 Jun 2021 02:32:06 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 43/45] include/qemu/lockable: Use _Generic instead of QEMU_GENERIC Date: Thu, 17 Jun 2021 11:31:32 +0200 Message-Id: <20210617093134.900014-44-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson This is both more and less complicated than our expansion using __builtin_choose_expr and __builtin_types_compatible_p. The expansion through QEMU_MAKE_LOCKABLE_ doesn't work because we're not emumerating all of the types within the same _Generic, which results in errors about unhandled cases. We must also handle void* explicitly, so that the NULL constant can be used. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Tested-by: Alex Bennée Message-Id: <20210614233143.1221879-7-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- include/qemu/lockable.h | 90 +++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h index b620023141..86db7cb04c 100644 --- a/include/qemu/lockable.h +++ b/include/qemu/lockable.h @@ -24,79 +24,71 @@ struct QemuLockable { QemuLockUnlockFunc *unlock; }; -/* This function gives an error if an invalid, non-NULL pointer type is passed - * to QEMU_MAKE_LOCKABLE. For optimized builds, we can rely on dead-code elimination - * from the compiler, and give the errors already at link time. - */ -#if defined(__OPTIMIZE__) && !defined(__SANITIZE_ADDRESS__) -void unknown_lock_type(void *); -#else -static inline void unknown_lock_type(void *unused) -{ - abort(); -} -#endif - static inline __attribute__((__always_inline__)) QemuLockable * qemu_make_lockable(void *x, QemuLockable *lockable) { - /* We cannot test this in a macro, otherwise we get compiler + /* + * We cannot test this in a macro, otherwise we get compiler * warnings like "the address of 'm' will always evaluate as 'true'". */ return x ? lockable : NULL; } -/* Auxiliary macros to simplify QEMU_MAKE_LOCABLE. */ -#define QEMU_LOCK_FUNC(x) ((QemuLockUnlockFunc *) \ - QEMU_GENERIC(x, \ - (QemuMutex *, qemu_mutex_lock), \ - (QemuRecMutex *, qemu_rec_mutex_lock), \ - (CoMutex *, qemu_co_mutex_lock), \ - (QemuSpin *, qemu_spin_lock), \ - unknown_lock_type)) +static inline __attribute__((__always_inline__)) QemuLockable * +qemu_null_lockable(void *x) +{ + if (x != NULL) { + qemu_build_not_reached(); + } + return NULL; +} -#define QEMU_UNLOCK_FUNC(x) ((QemuLockUnlockFunc *) \ - QEMU_GENERIC(x, \ - (QemuMutex *, qemu_mutex_unlock), \ - (QemuRecMutex *, qemu_rec_mutex_unlock), \ - (CoMutex *, qemu_co_mutex_unlock), \ - (QemuSpin *, qemu_spin_unlock), \ - unknown_lock_type)) - -/* In C, compound literals have the lifetime of an automatic variable. +/* + * In C, compound literals have the lifetime of an automatic variable. * In C++ it would be different, but then C++ wouldn't need QemuLockable * either... */ -#define QEMU_MAKE_LOCKABLE_(x) (&(QemuLockable) { \ - .object = (x), \ - .lock = QEMU_LOCK_FUNC(x), \ - .unlock = QEMU_UNLOCK_FUNC(x), \ +#define QML_OBJ_(x, name) (&(QemuLockable) { \ + .object = (x), \ + .lock = (QemuLockUnlockFunc *) qemu_ ## name ## _lock, \ + .unlock = (QemuLockUnlockFunc *) qemu_ ## name ## _unlock \ }) -/* QEMU_MAKE_LOCKABLE - Make a polymorphic QemuLockable +/** + * QEMU_MAKE_LOCKABLE - Make a polymorphic QemuLockable * - * @x: a lock object (currently one of QemuMutex, QemuRecMutex, CoMutex, QemuSpin). + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, + * CoMutex, QemuSpin). * * Returns a QemuLockable object that can be passed around * to a function that can operate with locks of any kind, or * NULL if @x is %NULL. - */ -#define QEMU_MAKE_LOCKABLE(x) \ - QEMU_GENERIC(x, \ - (QemuLockable *, (x)), \ - qemu_make_lockable((x), QEMU_MAKE_LOCKABLE_(x))) - -/* QEMU_MAKE_LOCKABLE_NONNULL - Make a polymorphic QemuLockable * - * @x: a lock object (currently one of QemuMutex, QemuRecMutex, CoMutex, QemuSpin). + * Note the special case for void *, so that we may pass "NULL". + */ +#define QEMU_MAKE_LOCKABLE(x) \ + _Generic((x), QemuLockable *: (x), \ + void *: qemu_null_lockable(x), \ + QemuMutex *: qemu_make_lockable(x, QML_OBJ_(x, mutex)), \ + QemuRecMutex *: qemu_make_lockable(x, QML_OBJ_(x, rec_mutex)), \ + CoMutex *: qemu_make_lockable(x, QML_OBJ_(x, co_mutex)), \ + QemuSpin *: qemu_make_lockable(x, QML_OBJ_(x, spin))) + +/** + * QEMU_MAKE_LOCKABLE_NONNULL - Make a polymorphic QemuLockable + * + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, + * CoMutex, QemuSpin). * * Returns a QemuLockable object that can be passed around * to a function that can operate with locks of any kind. */ -#define QEMU_MAKE_LOCKABLE_NONNULL(x) \ - QEMU_GENERIC(x, \ - (QemuLockable *, (x)), \ - QEMU_MAKE_LOCKABLE_(x)) +#define QEMU_MAKE_LOCKABLE_NONNULL(x) \ + _Generic((x), QemuLockable *: (x), \ + QemuMutex *: QML_OBJ_(x, mutex), \ + QemuRecMutex *: QML_OBJ_(x, rec_mutex), \ + CoMutex *: QML_OBJ_(x, co_mutex), \ + QemuSpin *: QML_OBJ_(x, spin)) static inline void qemu_lockable_lock(QemuLockable *x) { From patchwork Thu Jun 17 09:31:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43DF0C2B9F4 for ; Thu, 17 Jun 2021 10:00:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EF559611CE for ; Thu, 17 Jun 2021 10:00:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF559611CE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltopV-0006ZH-Ny for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 06:00:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNe-0003Fl-Vc for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:11 -0400 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]:38905) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNc-0006Rx-SZ for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:10 -0400 Received: by mail-ed1-x52c.google.com with SMTP id t7so3048386edd.5 for ; Thu, 17 Jun 2021 02:32: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=w/ZDHFj/sj/zgSbYdluGkx019Z0PuVQHSdt6mo9xSR4=; b=MrXphbJ/KQ/joNv3lsNS+yXiCVYhwrhLx7EMEn7Vn5FnZDoEJYaGcdhq2EdPGPtiKo DmV+fRLDkrI8LUVLV4h4pNq1QdIiuV1G+i6NAxp0BF3GFi3oBWM+C9COjQIzhxwWV0kI IWJfbjiESS9MP4TpyxKLD/V+DQqkLEf2B8LNpLvRkitvIUkDGsozkxC363lg0goGjZcD WR65MTwpPYBQhavnWIQmyGE0Z2Zcu6c5zm4HM6SBnrewFOx0hRqeEGUwc7urmIqlSfm8 U9vTwYTUU6sTK53VpMUzpBOWAmtKzHBjKHKzJroeBTofmvw8e4gdO4cCnMNXkS7zcaCw 1fdg== 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=w/ZDHFj/sj/zgSbYdluGkx019Z0PuVQHSdt6mo9xSR4=; b=ta+od7WrDDBMs6WESGz6bwYPRJhLBoAmsY3Ig2cBRrRVJsbw930EeGRGFhZEs58iBR s7uj6NQWM4SUJ8sEzlprR/IOK3i6aTqg12IibL7HZ30KAv+v87r4I5ndOdnoo740wX6a rl81jNLQ3lWqujuDfBb/J97xX3OpICcI7Pr7/0NPkObwpQM8fj+jWfdKOOlsZf7z7npV rJe8Cb80W9Dyn1e+YCv7B2Mvb5rUrhA/w/i/r8eMYnaWz+PGeD1ZwogEyH8PCQ4L0Xbd DHNuseUZ/s6hHO+StfOgafTNC8Z28QyKtU4A8aIFu2mG75pmY0OQUFAPGJvwwIHJSpko OdoQ== X-Gm-Message-State: AOAM530h7hFLzWOY9LTrKo2GpwXX1N55NTtFZdLN8HrIXpdoO+Dfocnt 5Ox0WDkZV2+crBGZ3HdmAQ1hVqNaaYw= X-Google-Smtp-Source: ABdhPJyX2CpCY2nViwaOkdKd9GB2hxpNwkxQk4JXb+kLwNx8I+SfQY+aFbsYNxGqSXw4l6XA3uH2Wg== X-Received: by 2002:a05:6402:4255:: with SMTP id g21mr5252335edb.103.1623922327685; Thu, 17 Jun 2021 02:32:07 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:07 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 44/45] qemu/compiler: Remove QEMU_GENERIC Date: Thu, 17 Jun 2021 11:31:33 +0200 Message-Id: <20210617093134.900014-45-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson All previous users now use C11 _Generic. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Message-Id: <20210614233143.1221879-8-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- include/qemu/compiler.h | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 091c45248b..5766d61589 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -173,46 +173,6 @@ #define QEMU_ALWAYS_INLINE #endif -/* Implement C11 _Generic via GCC builtins. Example: - * - * QEMU_GENERIC(x, (float, sinf), (long double, sinl), sin) (x) - * - * The first argument is the discriminator. The last is the default value. - * The middle ones are tuples in "(type, expansion)" format. - */ - -/* First, find out the number of generic cases. */ -#define QEMU_GENERIC(x, ...) \ - QEMU_GENERIC_(typeof(x), __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) - -/* There will be extra arguments, but they are not used. */ -#define QEMU_GENERIC_(x, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, count, ...) \ - QEMU_GENERIC##count(x, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) - -/* Two more helper macros, this time to extract items from a parenthesized - * list. - */ -#define QEMU_FIRST_(a, b) a -#define QEMU_SECOND_(a, b) b - -/* ... and a final one for the common part of the "recursion". */ -#define QEMU_GENERIC_IF(x, type_then, else_) \ - __builtin_choose_expr(__builtin_types_compatible_p(x, \ - QEMU_FIRST_ type_then), \ - QEMU_SECOND_ type_then, else_) - -/* CPP poor man's "recursion". */ -#define QEMU_GENERIC1(x, a0, ...) (a0) -#define QEMU_GENERIC2(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC1(x, __VA_ARGS__)) -#define QEMU_GENERIC3(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC2(x, __VA_ARGS__)) -#define QEMU_GENERIC4(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC3(x, __VA_ARGS__)) -#define QEMU_GENERIC5(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC4(x, __VA_ARGS__)) -#define QEMU_GENERIC6(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC5(x, __VA_ARGS__)) -#define QEMU_GENERIC7(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC6(x, __VA_ARGS__)) -#define QEMU_GENERIC8(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC7(x, __VA_ARGS__)) -#define QEMU_GENERIC9(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC8(x, __VA_ARGS__)) -#define QEMU_GENERIC10(x, a0, ...) QEMU_GENERIC_IF(x, a0, QEMU_GENERIC9(x, __VA_ARGS__)) - /** * qemu_build_not_reached() * From patchwork Thu Jun 17 09:31:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 12327213 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59736C2B9F4 for ; Thu, 17 Jun 2021 09:52:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0E507613EC for ; Thu, 17 Jun 2021 09:52:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E507613EC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltohj-0007J0-53 for qemu-devel@archiver.kernel.org; Thu, 17 Jun 2021 05:52:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltoNg-0003IB-Md for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:12 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:44941) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ltoNe-0006S6-Mo for qemu-devel@nongnu.org; Thu, 17 Jun 2021 05:32:12 -0400 Received: by mail-ej1-x633.google.com with SMTP id gt18so8690176ejc.11 for ; Thu, 17 Jun 2021 02:32: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=Ih1xddWmyW9WnFhSZ9eRiE6DF/hMjeq/MCb4afEYuBY=; b=IK2Zaum/1R3bz4w0YCSAYB1xPl3BAL3bv/jzV/qr8GZ3e4GgqE1zFA+fsl10B1hWGL tyomFaEfRxoL/69R0kBFbX2cZ7w0PMGJh7fp2Z54hiEqnsofE/ME1xDnrXrxzHkDJ8qc BcENH/nGv4RYXmLwM83vA9sGKvAi/J+/6SV96uvDT/lpnwV65rGqOlypkIrqm7oAxgG9 GNpJhDJirvH5H+mz8oR8DgqaTftGMDMzgx1d0ej4DHyUB7Puq1fTJgUYNQnAunOuHFw6 smwogOsW+8O1V6LKX/cxO21w/LdCXuYfLchIOP9noJE/3Am/um9jug/JK95boZwuklTt elpg== 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=Ih1xddWmyW9WnFhSZ9eRiE6DF/hMjeq/MCb4afEYuBY=; b=nROjfuTyg6q29o7epfxzUqqAJqnGGCynl0sSjHsx+6DUFnHPf4e0fabib72/UN0Nm5 YLuPlrQSmujwVYXN9a5ljm2vlsKLKv2Y85eiWvZawKSx2xwNWe7yDecZUSBZf1mgylkM XaQpJtJ1KxfjvGUvjTH/AcAjpN8VtuzY0QvnDtOuINBElI9qx8TEDE19a5scp7MIWDJ7 kNl/KUPC6alxhs34AkL/zkEy2WS+uPNQTK+qgh9ljlSnnnTs2dfxw/nYM5a3KJtgs+Go fCghkGgK5l1wIlHB7nIK4hjiwWtYDUuNlfGmbU8OyDcb4SN4yVFejcc4FS+GdjW4T6w5 soiw== X-Gm-Message-State: AOAM531DqT3YDViZw3pjl36+rOCA0L0JKCwPErK1S0vdzGLjg8r2gqRV wNyX/4y8T4RsMK4df9ctqx1Ov2ky25U= X-Google-Smtp-Source: ABdhPJwZU2hxN+vBE8WItKOUpqhAHst8eyd5aYr8s7qLE9dXiiubltDGg+AMwXt5nf2/K6k+rrRTLg== X-Received: by 2002:a17:906:670c:: with SMTP id a12mr4118558ejp.249.1623922328333; Thu, 17 Jun 2021 02:32:08 -0700 (PDT) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id m18sm3328140ejx.56.2021.06.17.02.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jun 2021 02:32:08 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 45/45] configure: Remove probe for _Static_assert Date: Thu, 17 Jun 2021 11:31:34 +0200 Message-Id: <20210617093134.900014-46-pbonzini@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210617093134.900014-1-pbonzini@redhat.com> References: <20210617093134.900014-1-pbonzini@redhat.com> MIME-Version: 1.0 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.248, 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?Alex_Benn=C3=A9e?= , Thomas Huth , Richard Henderson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson _Static_assert is part of C11, which is now required. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée Reviewed-by: Thomas Huth Message-Id: <20210614233143.1221879-9-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- configure | 18 ------------------ include/qemu/compiler.h | 11 ----------- 2 files changed, 29 deletions(-) diff --git a/configure b/configure index ebc016111a..262ab71802 100755 --- a/configure +++ b/configure @@ -5090,20 +5090,6 @@ if compile_prog "" "" ; then have_sysmacros=yes fi -########################################## -# check for _Static_assert() - -have_static_assert=no -cat > $TMPC << EOF -_Static_assert(1, "success"); -int main(void) { - return 0; -} -EOF -if compile_prog "" "" ; then - have_static_assert=yes -fi - ########################################## # check for utmpx.h, it is missing e.g. on OpenBSD @@ -6035,10 +6021,6 @@ if test "$have_sysmacros" = "yes" ; then echo "CONFIG_SYSMACROS=y" >> $config_host_mak fi -if test "$have_static_assert" = "yes" ; then - echo "CONFIG_STATIC_ASSERT=y" >> $config_host_mak -fi - if test "$have_utmpx" = "yes" ; then echo "HAVE_UTMPX=y" >> $config_host_mak fi diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 5766d61589..3baa5e3790 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -72,18 +72,7 @@ int:(x) ? -1 : 1; \ } -/* QEMU_BUILD_BUG_MSG() emits the message given if _Static_assert is - * supported; otherwise, it will be omitted from the compiler error - * message (but as it remains present in the source code, it can still - * be useful when debugging). */ -#if defined(CONFIG_STATIC_ASSERT) #define QEMU_BUILD_BUG_MSG(x, msg) _Static_assert(!(x), msg) -#elif defined(__COUNTER__) -#define QEMU_BUILD_BUG_MSG(x, msg) typedef QEMU_BUILD_BUG_ON_STRUCT(x) \ - glue(qemu_build_bug_on__, __COUNTER__) __attribute__((unused)) -#else -#define QEMU_BUILD_BUG_MSG(x, msg) -#endif #define QEMU_BUILD_BUG_ON(x) QEMU_BUILD_BUG_MSG(x, "not expecting: " #x)