From patchwork Fri Jan 8 16:45:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TBqSvLFh; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8DG6VwWz9sW8 for ; Sat, 9 Jan 2021 03:47:58 +1100 (AEDT) Received: from localhost ([::1]:44538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxuvb-0004EU-2l for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 11:47:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuu9-0004Ce-EG for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:46:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxutu-0003fR-DK for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:46:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=53Byod/raVq1cruhMmN1Dc7/qzuu1tuV79jjDpV/HPE=; b=TBqSvLFhkmktQ/rLrbKAY4gtcXZ99qNyLgI2pv1QRw23IuixRjUzX5V6/fottsR1LcEBzG RO/nTUyCCVPsv2dPxZdpfG9NDWenjBFtkYbk7JAE91hbScJ8MD3325KFetcciEimOblWS5 r2pxBUWwS/giJFX34J3qkAORlakR8EU= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-35-0FFFLb7pNkWqe9e3yHGLaQ-1; Fri, 08 Jan 2021 11:46:05 -0500 X-MC-Unique: 0FFFLb7pNkWqe9e3yHGLaQ-1 Received: by mail-qv1-f69.google.com with SMTP id i20so8637811qvk.18 for ; Fri, 08 Jan 2021 08:46:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=53Byod/raVq1cruhMmN1Dc7/qzuu1tuV79jjDpV/HPE=; b=fekN53JixSP6QD43dJbdJe4OHkQr73jHS98Yf1dUSJGMkULwl4P5Z4T/b9nV95Johe pdDkaJPAE0u1/WIAYlEOu4lzmyGwinuVBXFI4nutDP4Rs4i8E+QnDE6/gDYGqBWKH6GV QHedaJnNRURMbX3exwp2gQRqpC4UAWdR3uxmDLfBzuhMEHbGJc6cFKbhgYpppnbUK7No LU8p/tDIuNfOSd7n4TtKUrVQ7/7LirjteQjAYTEakeodTiq9YJC69CirlJr7pb16wFDb 6Z73nDeGJPrXD9QGLBGYMJIICir8BfKLEUkRlZ7HHkXLx2+9seIw0Wl/uyrjfKox3uCu 5oQA== X-Gm-Message-State: AOAM530HOvqhAHYU3m+mH2lC0UzmhSf9qOCF/K8sEPlTeaaq75RjBzJ5 AuLGYPluzhKhniqjiNifhGK73X+S2bHc01rfK7xTBZLEjiHdkDQZAD/nrmTdn7ZyfbixQoh9Tv2 S3mamAVRtbHgCwb7LoH+ih4NB+L6U/oZp0XnMwKeRugWq+cVOwDrhnHCVAwq/8mzG X-Received: by 2002:a0c:b989:: with SMTP id v9mr7606900qvf.42.1610124364499; Fri, 08 Jan 2021 08:46:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJzii5MMHh4GOF+EEbY3ymFhWJMjmrNVmNmDTuGzI6EW7rfxiJVmCEiWz6aNIn0AZXevDWIdJA== X-Received: by 2002:a0c:b989:: with SMTP id v9mr7606887qvf.42.1610124364305; Fri, 08 Jan 2021 08:46:04 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id c139sm5067437qke.24.2021.01.08.08.46.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:46:03 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 01/13] update-linux-headers: Include const.h Date: Fri, 8 Jan 2021 11:45:49 -0500 Message-Id: <20210108164601.406146-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108164601.406146-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Eric Farman , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Farman Kernel commit a85cbe6159ff ("uapi: move constants from to ") breaks our script because of the unrecognized include. Let's add that to our processing. Signed-off-by: Eric Farman --- scripts/update-linux-headers.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/update-linux-headers.sh b/scripts/update-linux-headers.sh index 9efbaf2f84..fa6f2b6272 100755 --- a/scripts/update-linux-headers.sh +++ b/scripts/update-linux-headers.sh @@ -41,6 +41,7 @@ cp_portable() { -e 'pvrdma_verbs' \ -e 'drm.h' \ -e 'limits' \ + -e 'linux/const' \ -e 'linux/kernel' \ -e 'linux/sysinfo' \ -e 'asm-generic/kvm_para' \ @@ -190,7 +191,9 @@ for i in "$tmpdir"/include/linux/*virtio*.h \ "$tmpdir/include/linux/input.h" \ "$tmpdir/include/linux/input-event-codes.h" \ "$tmpdir/include/linux/pci_regs.h" \ - "$tmpdir/include/linux/ethtool.h" "$tmpdir/include/linux/kernel.h" \ + "$tmpdir/include/linux/ethtool.h" \ + "$tmpdir/include/linux/const.h" \ + "$tmpdir/include/linux/kernel.h" \ "$tmpdir/include/linux/vhost_types.h" \ "$tmpdir/include/linux/sysinfo.h"; do cp_portable "$i" "$output/include/standard-headers/linux" From patchwork Fri Jan 8 16:45:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423884 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QMYkFrTy; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8M81lktz9sW8 for ; Sat, 9 Jan 2021 03:53:56 +1100 (AEDT) Received: from localhost ([::1]:54852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxv1O-0000Rk-6g for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 11:53:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuu3-0004AQ-U2 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:46:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45255) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxutx-0003m7-RW for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:46:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124371; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WWOM/ylHVJ8N58DG1tDc9z8aI7aBJ+YRpssrEY49nxQ=; b=QMYkFrTyDyTqhE7lH7DlQ2mdn0uI2HDBdDfag9Jvg2I6PCmjBGVKNwxSanfSdUNxIcMyLG ClEh3SbtL7kXwg3/1O6DCU0xGK+2dgAeV/VwKLPN2cjPqfWjr+cygf7Po0oQZ34wnJ9Fff wv37CY9l3oFEmSLwty90xWjqW5f4nXA= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-148-veihdWboPsuZMcfdwJzZwg-1; Fri, 08 Jan 2021 11:46:09 -0500 X-MC-Unique: veihdWboPsuZMcfdwJzZwg-1 Received: by mail-qv1-f70.google.com with SMTP id t16so8668335qvk.13 for ; Fri, 08 Jan 2021 08:46:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WWOM/ylHVJ8N58DG1tDc9z8aI7aBJ+YRpssrEY49nxQ=; b=fvHjw8v7QV5gMesT6DtKLgpdjkhUsBrlQuSuWMwQ2o+4fFf5D3fvcgmdJkyHOq6oHG tWWvABExJ8EXBXaZsSRZys/5CKxmv06nRU/0hKxV1hB8GjLTY7MdfVo1FEox7cuxJglq KJ+J85RnFYxgy6rHyZ20NHfRu6ergCY/8vjrZ12qYt9+15LaI+6Ii3Bss6Mgh3KzKxA5 EOJQhACJnuHp9R5zKOmJUU0bU+HRc/dz7jl/sK3GRUwx0H1ktvH1yuGnKLvQK2fOtixH 5nwfHOEfrieisjn71rzvNqaYJHTcLgFTfiUPrkyekmGMiNBtCFI6IAaKuQKwZc9eN5gQ SM0Q== X-Gm-Message-State: AOAM533W5cp9MS/JMjV4kT0mFjIheTWpmeBAD/dbP52q7hThFJENrvOY GWAdlo5fEXcBiVMgHRXGWveWW+5HwUpg88PghDIuVncAB/cd+OLzwR6mQQPatXfUAyfQ2k7jiQJ Q37cUEWKmUgvWC+o5CfuU2aTqulwA3HgzwPafja4MR2OUrlTPxrN5kC+GWf9eamjM X-Received: by 2002:ac8:6987:: with SMTP id o7mr4116239qtq.295.1610124366949; Fri, 08 Jan 2021 08:46:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWP8+qo6kb63PylBDFwZqdKeF5IMynCCb+rXMJ4H7ano5q+aZfdKpHsuRxNZqbTK+JCeq/2Q== X-Received: by 2002:ac8:6987:: with SMTP id o7mr4116191qtq.295.1610124366264; Fri, 08 Jan 2021 08:46:06 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id c139sm5067437qke.24.2021.01.08.08.46.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:46:05 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 02/13] Update linux headers to 5.11-rc2 Date: Fri, 8 Jan 2021 11:45:50 -0500 Message-Id: <20210108164601.406146-3-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108164601.406146-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Eric Farman , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Farman Signed-off-by: Eric Farman --- .../infiniband/hw/vmw_pvrdma/pvrdma_ring.h | 14 +- .../infiniband/hw/vmw_pvrdma/pvrdma_verbs.h | 2 +- include/standard-headers/drm/drm_fourcc.h | 175 +++++++++++++++++- include/standard-headers/linux/const.h | 36 ++++ include/standard-headers/linux/ethtool.h | 2 +- include/standard-headers/linux/fuse.h | 30 ++- include/standard-headers/linux/kernel.h | 9 +- include/standard-headers/linux/pci_regs.h | 16 ++ include/standard-headers/linux/vhost_types.h | 9 + include/standard-headers/linux/virtio_gpu.h | 82 ++++++++ include/standard-headers/linux/virtio_ids.h | 44 +++-- linux-headers/asm-arm64/kvm.h | 3 - linux-headers/asm-generic/unistd.h | 6 +- linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 1 + linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 1 + linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/kvm.h | 56 +++++- linux-headers/linux/userfaultfd.h | 9 + linux-headers/linux/vfio.h | 1 + linux-headers/linux/vhost.h | 4 + 28 files changed, 461 insertions(+), 48 deletions(-) create mode 100644 include/standard-headers/linux/const.h diff --git a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h b/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h index 7b4062a1a1..acd4c8346d 100644 --- a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h +++ b/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h @@ -68,7 +68,7 @@ static inline int pvrdma_idx_valid(uint32_t idx, uint32_t max_elems) static inline int32_t pvrdma_idx(int *var, uint32_t max_elems) { - const unsigned int idx = qatomic_read(var); + const unsigned int idx = atomic_read(var); if (pvrdma_idx_valid(idx, max_elems)) return idx & (max_elems - 1); @@ -77,17 +77,17 @@ static inline int32_t pvrdma_idx(int *var, uint32_t max_elems) static inline void pvrdma_idx_ring_inc(int *var, uint32_t max_elems) { - uint32_t idx = qatomic_read(var) + 1; /* Increment. */ + uint32_t idx = atomic_read(var) + 1; /* Increment. */ idx &= (max_elems << 1) - 1; /* Modulo size, flip gen. */ - qatomic_set(var, idx); + atomic_set(var, idx); } static inline int32_t pvrdma_idx_ring_has_space(const struct pvrdma_ring *r, uint32_t max_elems, uint32_t *out_tail) { - const uint32_t tail = qatomic_read(&r->prod_tail); - const uint32_t head = qatomic_read(&r->cons_head); + const uint32_t tail = atomic_read(&r->prod_tail); + const uint32_t head = atomic_read(&r->cons_head); if (pvrdma_idx_valid(tail, max_elems) && pvrdma_idx_valid(head, max_elems)) { @@ -100,8 +100,8 @@ static inline int32_t pvrdma_idx_ring_has_space(const struct pvrdma_ring *r, static inline int32_t pvrdma_idx_ring_has_data(const struct pvrdma_ring *r, uint32_t max_elems, uint32_t *out_head) { - const uint32_t tail = qatomic_read(&r->prod_tail); - const uint32_t head = qatomic_read(&r->cons_head); + const uint32_t tail = atomic_read(&r->prod_tail); + const uint32_t head = atomic_read(&r->cons_head); if (pvrdma_idx_valid(tail, max_elems) && pvrdma_idx_valid(head, max_elems)) { diff --git a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h b/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h index 0a8c7c9311..1677208a41 100644 --- a/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h +++ b/include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h @@ -176,7 +176,7 @@ struct pvrdma_port_attr { uint8_t subnet_timeout; uint8_t init_type_reply; uint8_t active_width; - uint16_t active_speed; + uint8_t active_speed; uint8_t phys_state; uint8_t reserved[2]; }; diff --git a/include/standard-headers/drm/drm_fourcc.h b/include/standard-headers/drm/drm_fourcc.h index 0de1a552ca..c47e19810c 100644 --- a/include/standard-headers/drm/drm_fourcc.h +++ b/include/standard-headers/drm/drm_fourcc.h @@ -57,6 +57,30 @@ extern "C" { * may preserve meaning - such as number of planes - from the fourcc code, * whereas others may not. * + * Modifiers must uniquely encode buffer layout. In other words, a buffer must + * match only a single modifier. A modifier must not be a subset of layouts of + * another modifier. For instance, it's incorrect to encode pitch alignment in + * a modifier: a buffer may match a 64-pixel aligned modifier and a 32-pixel + * aligned modifier. That said, modifiers can have implicit minimal + * requirements. + * + * For modifiers where the combination of fourcc code and modifier can alias, + * a canonical pair needs to be defined and used by all drivers. Preferred + * combinations are also encouraged where all combinations might lead to + * confusion and unnecessarily reduced interoperability. An example for the + * latter is AFBC, where the ABGR layouts are preferred over ARGB layouts. + * + * There are two kinds of modifier users: + * + * - Kernel and user-space drivers: for drivers it's important that modifiers + * don't alias, otherwise two drivers might support the same format but use + * different aliases, preventing them from sharing buffers in an efficient + * format. + * - Higher-level programs interfacing with KMS/GBM/EGL/Vulkan/etc: these users + * see modifiers as opaque tokens they can check for equality and intersect. + * These users musn't need to know to reason about the modifier value + * (i.e. they are not expected to extract information out of the modifier). + * * Vendors should document their modifier usage in as much detail as * possible, to ensure maximum compatibility across devices, drivers and * applications. @@ -154,6 +178,12 @@ extern "C" { #define DRM_FORMAT_ARGB16161616F fourcc_code('A', 'R', '4', 'H') /* [63:0] A:R:G:B 16:16:16:16 little endian */ #define DRM_FORMAT_ABGR16161616F fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */ +/* + * RGBA format with 10-bit components packed in 64-bit per pixel, with 6 bits + * of unused padding per component: + */ +#define DRM_FORMAT_AXBXGXRX106106106106 fourcc_code('A', 'B', '1', '0') /* [63:0] A:x:B:x:G:x:R:x 10:6:10:6:10:6:10:6 little endian */ + /* packed YCbCr */ #define DRM_FORMAT_YUYV fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */ #define DRM_FORMAT_YVYU fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */ @@ -319,7 +349,6 @@ extern "C" { */ /* Vendor Ids: */ -#define DRM_FORMAT_MOD_NONE 0 #define DRM_FORMAT_MOD_VENDOR_NONE 0 #define DRM_FORMAT_MOD_VENDOR_INTEL 0x01 #define DRM_FORMAT_MOD_VENDOR_AMD 0x02 @@ -391,6 +420,16 @@ extern "C" { */ #define DRM_FORMAT_MOD_LINEAR fourcc_mod_code(NONE, 0) +/* + * Deprecated: use DRM_FORMAT_MOD_LINEAR instead + * + * The "none" format modifier doesn't actually mean that the modifier is + * implicit, instead it means that the layout is linear. Whether modifiers are + * used is out-of-band information carried in an API-specific way (e.g. in a + * flag for drm_mode_fb_cmd2). + */ +#define DRM_FORMAT_MOD_NONE 0 + /* Intel framebuffer modifiers */ /* @@ -1055,6 +1094,140 @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier) */ #define AMLOGIC_FBC_OPTION_MEM_SAVING (1ULL << 0) +/* + * AMD modifiers + * + * Memory layout: + * + * without DCC: + * - main surface + * + * with DCC & without DCC_RETILE: + * - main surface in plane 0 + * - DCC surface in plane 1 (RB-aligned, pipe-aligned if DCC_PIPE_ALIGN is set) + * + * with DCC & DCC_RETILE: + * - main surface in plane 0 + * - displayable DCC surface in plane 1 (not RB-aligned & not pipe-aligned) + * - pipe-aligned DCC surface in plane 2 (RB-aligned & pipe-aligned) + * + * For multi-plane formats the above surfaces get merged into one plane for + * each format plane, based on the required alignment only. + * + * Bits Parameter Notes + * ----- ------------------------ --------------------------------------------- + * + * 7:0 TILE_VERSION Values are AMD_FMT_MOD_TILE_VER_* + * 12:8 TILE Values are AMD_FMT_MOD_TILE__* + * 13 DCC + * 14 DCC_RETILE + * 15 DCC_PIPE_ALIGN + * 16 DCC_INDEPENDENT_64B + * 17 DCC_INDEPENDENT_128B + * 19:18 DCC_MAX_COMPRESSED_BLOCK Values are AMD_FMT_MOD_DCC_BLOCK_* + * 20 DCC_CONSTANT_ENCODE + * 23:21 PIPE_XOR_BITS Only for some chips + * 26:24 BANK_XOR_BITS Only for some chips + * 29:27 PACKERS Only for some chips + * 32:30 RB Only for some chips + * 35:33 PIPE Only for some chips + * 55:36 - Reserved for future use, must be zero + */ +#define AMD_FMT_MOD fourcc_mod_code(AMD, 0) + +#define IS_AMD_FMT_MOD(val) (((val) >> 56) == DRM_FORMAT_MOD_VENDOR_AMD) + +/* Reserve 0 for GFX8 and older */ +#define AMD_FMT_MOD_TILE_VER_GFX9 1 +#define AMD_FMT_MOD_TILE_VER_GFX10 2 +#define AMD_FMT_MOD_TILE_VER_GFX10_RBPLUS 3 + +/* + * 64K_S is the same for GFX9/GFX10/GFX10_RBPLUS and hence has GFX9 as canonical + * version. + */ +#define AMD_FMT_MOD_TILE_GFX9_64K_S 9 + +/* + * 64K_D for non-32 bpp is the same for GFX9/GFX10/GFX10_RBPLUS and hence has + * GFX9 as canonical version. + */ +#define AMD_FMT_MOD_TILE_GFX9_64K_D 10 +#define AMD_FMT_MOD_TILE_GFX9_64K_S_X 25 +#define AMD_FMT_MOD_TILE_GFX9_64K_D_X 26 +#define AMD_FMT_MOD_TILE_GFX9_64K_R_X 27 + +#define AMD_FMT_MOD_DCC_BLOCK_64B 0 +#define AMD_FMT_MOD_DCC_BLOCK_128B 1 +#define AMD_FMT_MOD_DCC_BLOCK_256B 2 + +#define AMD_FMT_MOD_TILE_VERSION_SHIFT 0 +#define AMD_FMT_MOD_TILE_VERSION_MASK 0xFF +#define AMD_FMT_MOD_TILE_SHIFT 8 +#define AMD_FMT_MOD_TILE_MASK 0x1F + +/* Whether DCC compression is enabled. */ +#define AMD_FMT_MOD_DCC_SHIFT 13 +#define AMD_FMT_MOD_DCC_MASK 0x1 + +/* + * Whether to include two DCC surfaces, one which is rb & pipe aligned, and + * one which is not-aligned. + */ +#define AMD_FMT_MOD_DCC_RETILE_SHIFT 14 +#define AMD_FMT_MOD_DCC_RETILE_MASK 0x1 + +/* Only set if DCC_RETILE = false */ +#define AMD_FMT_MOD_DCC_PIPE_ALIGN_SHIFT 15 +#define AMD_FMT_MOD_DCC_PIPE_ALIGN_MASK 0x1 + +#define AMD_FMT_MOD_DCC_INDEPENDENT_64B_SHIFT 16 +#define AMD_FMT_MOD_DCC_INDEPENDENT_64B_MASK 0x1 +#define AMD_FMT_MOD_DCC_INDEPENDENT_128B_SHIFT 17 +#define AMD_FMT_MOD_DCC_INDEPENDENT_128B_MASK 0x1 +#define AMD_FMT_MOD_DCC_MAX_COMPRESSED_BLOCK_SHIFT 18 +#define AMD_FMT_MOD_DCC_MAX_COMPRESSED_BLOCK_MASK 0x3 + +/* + * DCC supports embedding some clear colors directly in the DCC surface. + * However, on older GPUs the rendering HW ignores the embedded clear color + * and prefers the driver provided color. This necessitates doing a fastclear + * eliminate operation before a process transfers control. + * + * If this bit is set that means the fastclear eliminate is not needed for these + * embeddable colors. + */ +#define AMD_FMT_MOD_DCC_CONSTANT_ENCODE_SHIFT 20 +#define AMD_FMT_MOD_DCC_CONSTANT_ENCODE_MASK 0x1 + +/* + * The below fields are for accounting for per GPU differences. These are only + * relevant for GFX9 and later and if the tile field is *_X/_T. + * + * PIPE_XOR_BITS = always needed + * BANK_XOR_BITS = only for TILE_VER_GFX9 + * PACKERS = only for TILE_VER_GFX10_RBPLUS + * RB = only for TILE_VER_GFX9 & DCC + * PIPE = only for TILE_VER_GFX9 & DCC & (DCC_RETILE | DCC_PIPE_ALIGN) + */ +#define AMD_FMT_MOD_PIPE_XOR_BITS_SHIFT 21 +#define AMD_FMT_MOD_PIPE_XOR_BITS_MASK 0x7 +#define AMD_FMT_MOD_BANK_XOR_BITS_SHIFT 24 +#define AMD_FMT_MOD_BANK_XOR_BITS_MASK 0x7 +#define AMD_FMT_MOD_PACKERS_SHIFT 27 +#define AMD_FMT_MOD_PACKERS_MASK 0x7 +#define AMD_FMT_MOD_RB_SHIFT 30 +#define AMD_FMT_MOD_RB_MASK 0x7 +#define AMD_FMT_MOD_PIPE_SHIFT 33 +#define AMD_FMT_MOD_PIPE_MASK 0x7 + +#define AMD_FMT_MOD_SET(field, value) \ + ((uint64_t)(value) << AMD_FMT_MOD_##field##_SHIFT) +#define AMD_FMT_MOD_GET(field, value) \ + (((value) >> AMD_FMT_MOD_##field##_SHIFT) & AMD_FMT_MOD_##field##_MASK) +#define AMD_FMT_MOD_CLEAR(field) \ + (~((uint64_t)AMD_FMT_MOD_##field##_MASK << AMD_FMT_MOD_##field##_SHIFT)) + #if defined(__cplusplus) } #endif diff --git a/include/standard-headers/linux/const.h b/include/standard-headers/linux/const.h new file mode 100644 index 0000000000..5e48987251 --- /dev/null +++ b/include/standard-headers/linux/const.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* const.h: Macros for dealing with constants. */ + +#ifndef _LINUX_CONST_H +#define _LINUX_CONST_H + +/* Some constant macros are used in both assembler and + * C code. Therefore we cannot annotate them always with + * 'UL' and other type specifiers unilaterally. We + * use the following macros to deal with this. + * + * Similarly, _AT() will cast an expression with a type in C, but + * leave it unchanged in asm. + */ + +#ifdef __ASSEMBLY__ +#define _AC(X,Y) X +#define _AT(T,X) X +#else +#define __AC(X,Y) (X##Y) +#define _AC(X,Y) __AC(X,Y) +#define _AT(T,X) ((T)(X)) +#endif + +#define _UL(x) (_AC(x, UL)) +#define _ULL(x) (_AC(x, ULL)) + +#define _BITUL(x) (_UL(1) << (x)) +#define _BITULL(x) (_ULL(1) << (x)) + +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) + +#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) + +#endif /* _LINUX_CONST_H */ diff --git a/include/standard-headers/linux/ethtool.h b/include/standard-headers/linux/ethtool.h index 0df22f7538..8bfd01d230 100644 --- a/include/standard-headers/linux/ethtool.h +++ b/include/standard-headers/linux/ethtool.h @@ -16,7 +16,7 @@ #include "net/eth.h" -#include "standard-headers/linux/kernel.h" +#include "standard-headers/linux/const.h" #include "standard-headers/linux/types.h" #include "standard-headers/linux/if_ether.h" diff --git a/include/standard-headers/linux/fuse.h b/include/standard-headers/linux/fuse.h index 82c0a38b59..950d7edb7e 100644 --- a/include/standard-headers/linux/fuse.h +++ b/include/standard-headers/linux/fuse.h @@ -175,6 +175,10 @@ * * 7.32 * - add flags to fuse_attr, add FUSE_ATTR_SUBMOUNT, add FUSE_SUBMOUNTS + * + * 7.33 + * - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUIDGID + * - add FUSE_OPEN_KILL_SUIDGID */ #ifndef _LINUX_FUSE_H @@ -206,7 +210,7 @@ #define FUSE_KERNEL_VERSION 7 /** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 32 +#define FUSE_KERNEL_MINOR_VERSION 33 /** The node ID of the root inode */ #define FUSE_ROOT_ID 1 @@ -267,6 +271,7 @@ struct fuse_file_lock { #define FATTR_MTIME_NOW (1 << 8) #define FATTR_LOCKOWNER (1 << 9) #define FATTR_CTIME (1 << 10) +#define FATTR_KILL_SUIDGID (1 << 11) /** * Flags returned by the OPEN request @@ -316,6 +321,11 @@ struct fuse_file_lock { * foffset and moffset fields in struct * fuse_setupmapping_out and fuse_removemapping_one. * FUSE_SUBMOUNTS: kernel supports auto-mounting directory submounts + * FUSE_HANDLE_KILLPRIV_V2: fs kills suid/sgid/cap on write/chown/trunc. + * Upon write/truncate suid/sgid is only killed if caller + * does not have CAP_FSETID. Additionally upon + * write/truncate sgid is killed only if file has group + * execute permission. (Same as Linux VFS behavior). */ #define FUSE_ASYNC_READ (1 << 0) #define FUSE_POSIX_LOCKS (1 << 1) @@ -345,6 +355,7 @@ struct fuse_file_lock { #define FUSE_EXPLICIT_INVAL_DATA (1 << 25) #define FUSE_MAP_ALIGNMENT (1 << 26) #define FUSE_SUBMOUNTS (1 << 27) +#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28) /** * CUSE INIT request/reply flags @@ -374,11 +385,14 @@ struct fuse_file_lock { * * FUSE_WRITE_CACHE: delayed write from page cache, file handle is guessed * FUSE_WRITE_LOCKOWNER: lock_owner field is valid - * FUSE_WRITE_KILL_PRIV: kill suid and sgid bits + * FUSE_WRITE_KILL_SUIDGID: kill suid and sgid bits */ #define FUSE_WRITE_CACHE (1 << 0) #define FUSE_WRITE_LOCKOWNER (1 << 1) -#define FUSE_WRITE_KILL_PRIV (1 << 2) +#define FUSE_WRITE_KILL_SUIDGID (1 << 2) + +/* Obsolete alias; this flag implies killing suid/sgid only. */ +#define FUSE_WRITE_KILL_PRIV FUSE_WRITE_KILL_SUIDGID /** * Read flags @@ -427,6 +441,12 @@ struct fuse_file_lock { */ #define FUSE_ATTR_SUBMOUNT (1 << 0) +/** + * Open flags + * FUSE_OPEN_KILL_SUIDGID: Kill suid and sgid if executable + */ +#define FUSE_OPEN_KILL_SUIDGID (1 << 0) + enum fuse_opcode { FUSE_LOOKUP = 1, FUSE_FORGET = 2, /* no reply */ @@ -588,14 +608,14 @@ struct fuse_setattr_in { struct fuse_open_in { uint32_t flags; - uint32_t unused; + uint32_t open_flags; /* FUSE_OPEN_... */ }; struct fuse_create_in { uint32_t flags; uint32_t mode; uint32_t umask; - uint32_t padding; + uint32_t open_flags; /* FUSE_OPEN_... */ }; struct fuse_open_out { diff --git a/include/standard-headers/linux/kernel.h b/include/standard-headers/linux/kernel.h index 1eeba2ef92..7848c5ae25 100644 --- a/include/standard-headers/linux/kernel.h +++ b/include/standard-headers/linux/kernel.h @@ -3,13 +3,6 @@ #define _LINUX_KERNEL_H #include "standard-headers/linux/sysinfo.h" - -/* - * 'kernel.h' contains some often-used function prototypes etc - */ -#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) -#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) - -#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#include "standard-headers/linux/const.h" #endif /* _LINUX_KERNEL_H */ diff --git a/include/standard-headers/linux/pci_regs.h b/include/standard-headers/linux/pci_regs.h index a95d55f9f2..e709ae8235 100644 --- a/include/standard-headers/linux/pci_regs.h +++ b/include/standard-headers/linux/pci_regs.h @@ -531,6 +531,7 @@ #define PCI_EXP_LNKCAP_SLS_8_0GB 0x00000003 /* LNKCAP2 SLS Vector bit 2 */ #define PCI_EXP_LNKCAP_SLS_16_0GB 0x00000004 /* LNKCAP2 SLS Vector bit 3 */ #define PCI_EXP_LNKCAP_SLS_32_0GB 0x00000005 /* LNKCAP2 SLS Vector bit 4 */ +#define PCI_EXP_LNKCAP_SLS_64_0GB 0x00000006 /* LNKCAP2 SLS Vector bit 5 */ #define PCI_EXP_LNKCAP_MLW 0x000003f0 /* Maximum Link Width */ #define PCI_EXP_LNKCAP_ASPMS 0x00000c00 /* ASPM Support */ #define PCI_EXP_LNKCAP_ASPM_L0S 0x00000400 /* ASPM L0s Support */ @@ -562,6 +563,7 @@ #define PCI_EXP_LNKSTA_CLS_8_0GB 0x0003 /* Current Link Speed 8.0GT/s */ #define PCI_EXP_LNKSTA_CLS_16_0GB 0x0004 /* Current Link Speed 16.0GT/s */ #define PCI_EXP_LNKSTA_CLS_32_0GB 0x0005 /* Current Link Speed 32.0GT/s */ +#define PCI_EXP_LNKSTA_CLS_64_0GB 0x0006 /* Current Link Speed 64.0GT/s */ #define PCI_EXP_LNKSTA_NLW 0x03f0 /* Negotiated Link Width */ #define PCI_EXP_LNKSTA_NLW_X1 0x0010 /* Current Link Width x1 */ #define PCI_EXP_LNKSTA_NLW_X2 0x0020 /* Current Link Width x2 */ @@ -670,6 +672,7 @@ #define PCI_EXP_LNKCAP2_SLS_8_0GB 0x00000008 /* Supported Speed 8GT/s */ #define PCI_EXP_LNKCAP2_SLS_16_0GB 0x00000010 /* Supported Speed 16GT/s */ #define PCI_EXP_LNKCAP2_SLS_32_0GB 0x00000020 /* Supported Speed 32GT/s */ +#define PCI_EXP_LNKCAP2_SLS_64_0GB 0x00000040 /* Supported Speed 64GT/s */ #define PCI_EXP_LNKCAP2_CROSSLINK 0x00000100 /* Crosslink supported */ #define PCI_EXP_LNKCTL2 48 /* Link Control 2 */ #define PCI_EXP_LNKCTL2_TLS 0x000f @@ -678,6 +681,7 @@ #define PCI_EXP_LNKCTL2_TLS_8_0GT 0x0003 /* Supported Speed 8GT/s */ #define PCI_EXP_LNKCTL2_TLS_16_0GT 0x0004 /* Supported Speed 16GT/s */ #define PCI_EXP_LNKCTL2_TLS_32_0GT 0x0005 /* Supported Speed 32GT/s */ +#define PCI_EXP_LNKCTL2_TLS_64_0GT 0x0006 /* Supported Speed 64GT/s */ #define PCI_EXP_LNKCTL2_ENTER_COMP 0x0010 /* Enter Compliance */ #define PCI_EXP_LNKCTL2_TX_MARGIN 0x0380 /* Transmit Margin */ #define PCI_EXP_LNKCTL2_HASD 0x0020 /* HW Autonomous Speed Disable */ @@ -723,6 +727,7 @@ #define PCI_EXT_CAP_ID_DPC 0x1D /* Downstream Port Containment */ #define PCI_EXT_CAP_ID_L1SS 0x1E /* L1 PM Substates */ #define PCI_EXT_CAP_ID_PTM 0x1F /* Precision Time Measurement */ +#define PCI_EXT_CAP_ID_DVSEC 0x23 /* Designated Vendor-Specific */ #define PCI_EXT_CAP_ID_DLF 0x25 /* Data Link Feature */ #define PCI_EXT_CAP_ID_PL_16GT 0x26 /* Physical Layer 16.0 GT/s */ #define PCI_EXT_CAP_ID_MAX PCI_EXT_CAP_ID_PL_16GT @@ -831,6 +836,13 @@ #define PCI_PWR_CAP_BUDGET(x) ((x) & 1) /* Included in system budget */ #define PCI_EXT_CAP_PWR_SIZEOF 16 +/* Root Complex Event Collector Endpoint Association */ +#define PCI_RCEC_RCIEP_BITMAP 4 /* Associated Bitmap for RCiEPs */ +#define PCI_RCEC_BUSN 8 /* RCEC Associated Bus Numbers */ +#define PCI_RCEC_BUSN_REG_VER 0x02 /* Least version with BUSN present */ +#define PCI_RCEC_BUSN_NEXT(x) (((x) >> 8) & 0xff) +#define PCI_RCEC_BUSN_LAST(x) (((x) >> 16) & 0xff) + /* Vendor-Specific (VSEC, PCI_EXT_CAP_ID_VNDR) */ #define PCI_VNDR_HEADER 4 /* Vendor-Specific Header */ #define PCI_VNDR_HEADER_ID(x) ((x) & 0xffff) @@ -1066,6 +1078,10 @@ #define PCI_L1SS_CTL1_LTR_L12_TH_SCALE 0xe0000000 /* LTR_L1.2_THRESHOLD_Scale */ #define PCI_L1SS_CTL2 0x0c /* Control 2 Register */ +/* Designated Vendor-Specific (DVSEC, PCI_EXT_CAP_ID_DVSEC) */ +#define PCI_DVSEC_HEADER1 0x4 /* Designated Vendor-Specific Header1 */ +#define PCI_DVSEC_HEADER2 0x8 /* Designated Vendor-Specific Header2 */ + /* Data Link Feature */ #define PCI_DLF_CAP 0x04 /* Capabilities Register */ #define PCI_DLF_EXCHANGE_ENABLE 0x80000000 /* Data Link Feature Exchange Enable */ diff --git a/include/standard-headers/linux/vhost_types.h b/include/standard-headers/linux/vhost_types.h index 486630b332..0bd2684a2a 100644 --- a/include/standard-headers/linux/vhost_types.h +++ b/include/standard-headers/linux/vhost_types.h @@ -138,6 +138,15 @@ struct vhost_vdpa_config { uint8_t buf[0]; }; +/* vhost vdpa IOVA range + * @first: First address that can be mapped by vhost-vDPA + * @last: Last address that can be mapped by vhost-vDPA + */ +struct vhost_vdpa_iova_range { + uint64_t first; + uint64_t last; +}; + /* Feature bits */ /* Log all write descriptors. Can be changed while device is active. */ #define VHOST_F_LOG_ALL 26 diff --git a/include/standard-headers/linux/virtio_gpu.h b/include/standard-headers/linux/virtio_gpu.h index 4183cdc74b..1357e4774e 100644 --- a/include/standard-headers/linux/virtio_gpu.h +++ b/include/standard-headers/linux/virtio_gpu.h @@ -55,6 +55,11 @@ */ #define VIRTIO_GPU_F_RESOURCE_UUID 2 +/* + * VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB + */ +#define VIRTIO_GPU_F_RESOURCE_BLOB 3 + enum virtio_gpu_ctrl_type { VIRTIO_GPU_UNDEFINED = 0, @@ -71,6 +76,8 @@ enum virtio_gpu_ctrl_type { VIRTIO_GPU_CMD_GET_CAPSET, VIRTIO_GPU_CMD_GET_EDID, VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID, + VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB, + VIRTIO_GPU_CMD_SET_SCANOUT_BLOB, /* 3d commands */ VIRTIO_GPU_CMD_CTX_CREATE = 0x0200, @@ -81,6 +88,8 @@ enum virtio_gpu_ctrl_type { VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D, VIRTIO_GPU_CMD_SUBMIT_3D, + VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB, + VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB, /* cursor commands */ VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300, @@ -93,6 +102,7 @@ enum virtio_gpu_ctrl_type { VIRTIO_GPU_RESP_OK_CAPSET, VIRTIO_GPU_RESP_OK_EDID, VIRTIO_GPU_RESP_OK_RESOURCE_UUID, + VIRTIO_GPU_RESP_OK_MAP_INFO, /* error responses */ VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200, @@ -103,6 +113,15 @@ enum virtio_gpu_ctrl_type { VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER, }; +enum virtio_gpu_shm_id { + VIRTIO_GPU_SHM_ID_UNDEFINED = 0, + /* + * VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB + * VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB + */ + VIRTIO_GPU_SHM_ID_HOST_VISIBLE = 1 +}; + #define VIRTIO_GPU_FLAG_FENCE (1 << 0) struct virtio_gpu_ctrl_hdr { @@ -359,4 +378,67 @@ struct virtio_gpu_resp_resource_uuid { uint8_t uuid[16]; }; +/* VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB */ +struct virtio_gpu_resource_create_blob { + struct virtio_gpu_ctrl_hdr hdr; + uint32_t resource_id; +#define VIRTIO_GPU_BLOB_MEM_GUEST 0x0001 +#define VIRTIO_GPU_BLOB_MEM_HOST3D 0x0002 +#define VIRTIO_GPU_BLOB_MEM_HOST3D_GUEST 0x0003 + +#define VIRTIO_GPU_BLOB_FLAG_USE_MAPPABLE 0x0001 +#define VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE 0x0002 +#define VIRTIO_GPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004 + /* zero is invalid blob mem */ + uint32_t blob_mem; + uint32_t blob_flags; + uint32_t nr_entries; + uint64_t blob_id; + uint64_t size; + /* + * sizeof(nr_entries * virtio_gpu_mem_entry) bytes follow + */ +}; + +/* VIRTIO_GPU_CMD_SET_SCANOUT_BLOB */ +struct virtio_gpu_set_scanout_blob { + struct virtio_gpu_ctrl_hdr hdr; + struct virtio_gpu_rect r; + uint32_t scanout_id; + uint32_t resource_id; + uint32_t width; + uint32_t height; + uint32_t format; + uint32_t padding; + uint32_t strides[4]; + uint32_t offsets[4]; +}; + +/* VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB */ +struct virtio_gpu_resource_map_blob { + struct virtio_gpu_ctrl_hdr hdr; + uint32_t resource_id; + uint32_t padding; + uint64_t offset; +}; + +/* VIRTIO_GPU_RESP_OK_MAP_INFO */ +#define VIRTIO_GPU_MAP_CACHE_MASK 0x0f +#define VIRTIO_GPU_MAP_CACHE_NONE 0x00 +#define VIRTIO_GPU_MAP_CACHE_CACHED 0x01 +#define VIRTIO_GPU_MAP_CACHE_UNCACHED 0x02 +#define VIRTIO_GPU_MAP_CACHE_WC 0x03 +struct virtio_gpu_resp_map_info { + struct virtio_gpu_ctrl_hdr hdr; + uint32_t map_info; + uint32_t padding; +}; + +/* VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB */ +struct virtio_gpu_resource_unmap_blob { + struct virtio_gpu_ctrl_hdr hdr; + uint32_t resource_id; + uint32_t padding; +}; + #endif diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard-headers/linux/virtio_ids.h index b052355ac7..bc1c0621f5 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -29,24 +29,30 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#define VIRTIO_ID_NET 1 /* virtio net */ -#define VIRTIO_ID_BLOCK 2 /* virtio block */ -#define VIRTIO_ID_CONSOLE 3 /* virtio console */ -#define VIRTIO_ID_RNG 4 /* virtio rng */ -#define VIRTIO_ID_BALLOON 5 /* virtio balloon */ -#define VIRTIO_ID_RPMSG 7 /* virtio remote processor messaging */ -#define VIRTIO_ID_SCSI 8 /* virtio scsi */ -#define VIRTIO_ID_9P 9 /* 9p virtio console */ -#define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */ -#define VIRTIO_ID_CAIF 12 /* Virtio caif */ -#define VIRTIO_ID_GPU 16 /* virtio GPU */ -#define VIRTIO_ID_INPUT 18 /* virtio input */ -#define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ -#define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ -#define VIRTIO_ID_IOMMU 23 /* virtio IOMMU */ -#define VIRTIO_ID_MEM 24 /* virtio mem */ -#define VIRTIO_ID_FS 26 /* virtio filesystem */ -#define VIRTIO_ID_PMEM 27 /* virtio pmem */ -#define VIRTIO_ID_MAC80211_HWSIM 29 /* virtio mac80211-hwsim */ +#define VIRTIO_ID_NET 1 /* virtio net */ +#define VIRTIO_ID_BLOCK 2 /* virtio block */ +#define VIRTIO_ID_CONSOLE 3 /* virtio console */ +#define VIRTIO_ID_RNG 4 /* virtio rng */ +#define VIRTIO_ID_BALLOON 5 /* virtio balloon */ +#define VIRTIO_ID_IOMEM 6 /* virtio ioMemory */ +#define VIRTIO_ID_RPMSG 7 /* virtio remote processor messaging */ +#define VIRTIO_ID_SCSI 8 /* virtio scsi */ +#define VIRTIO_ID_9P 9 /* 9p virtio console */ +#define VIRTIO_ID_MAC80211_WLAN 10 /* virtio WLAN MAC */ +#define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */ +#define VIRTIO_ID_CAIF 12 /* Virtio caif */ +#define VIRTIO_ID_MEMORY_BALLOON 13 /* virtio memory balloon */ +#define VIRTIO_ID_GPU 16 /* virtio GPU */ +#define VIRTIO_ID_CLOCK 17 /* virtio clock/timer */ +#define VIRTIO_ID_INPUT 18 /* virtio input */ +#define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ +#define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ +#define VIRTIO_ID_SIGNAL_DIST 21 /* virtio signal distribution device */ +#define VIRTIO_ID_PSTORE 22 /* virtio pstore device */ +#define VIRTIO_ID_IOMMU 23 /* virtio IOMMU */ +#define VIRTIO_ID_MEM 24 /* virtio mem */ +#define VIRTIO_ID_FS 26 /* virtio filesystem */ +#define VIRTIO_ID_PMEM 27 /* virtio pmem */ +#define VIRTIO_ID_MAC80211_HWSIM 29 /* virtio mac80211-hwsim */ #endif /* _LINUX_VIRTIO_IDS_H */ diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h index a72de1ae4c..b6a0eaa32a 100644 --- a/linux-headers/asm-arm64/kvm.h +++ b/linux-headers/asm-arm64/kvm.h @@ -156,9 +156,6 @@ struct kvm_sync_regs { __u64 device_irq_level; }; -struct kvm_arch_memory_slot { -}; - /* * PMU filter structure. Describe a range of events with a particular * action. To be used with KVM_ARM_VCPU_PMU_V3_FILTER. diff --git a/linux-headers/asm-generic/unistd.h b/linux-headers/asm-generic/unistd.h index 2056318988..7287529177 100644 --- a/linux-headers/asm-generic/unistd.h +++ b/linux-headers/asm-generic/unistd.h @@ -517,7 +517,7 @@ __SC_COMP(__NR_settimeofday, sys_settimeofday, compat_sys_settimeofday) __SC_3264(__NR_adjtimex, sys_adjtimex_time32, sys_adjtimex) #endif -/* kernel/timer.c */ +/* kernel/sys.c */ #define __NR_getpid 172 __SYSCALL(__NR_getpid, sys_getpid) #define __NR_getppid 173 @@ -859,9 +859,11 @@ __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) __SYSCALL(__NR_faccessat2, sys_faccessat2) #define __NR_process_madvise 440 __SYSCALL(__NR_process_madvise, sys_process_madvise) +#define __NR_epoll_pwait2 441 +__SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2) #undef __NR_syscalls -#define __NR_syscalls 441 +#define __NR_syscalls 442 /* * 32 bit systems traditionally used different diff --git a/linux-headers/asm-mips/unistd_n32.h b/linux-headers/asm-mips/unistd_n32.h index aba284d190..59e53b6e07 100644 --- a/linux-headers/asm-mips/unistd_n32.h +++ b/linux-headers/asm-mips/unistd_n32.h @@ -370,6 +370,7 @@ #define __NR_pidfd_getfd (__NR_Linux + 438) #define __NR_faccessat2 (__NR_Linux + 439) #define __NR_process_madvise (__NR_Linux + 440) +#define __NR_epoll_pwait2 (__NR_Linux + 441) #endif /* _ASM_MIPS_UNISTD_N32_H */ diff --git a/linux-headers/asm-mips/unistd_n64.h b/linux-headers/asm-mips/unistd_n64.h index 0465ab94db..683558a7f8 100644 --- a/linux-headers/asm-mips/unistd_n64.h +++ b/linux-headers/asm-mips/unistd_n64.h @@ -346,6 +346,7 @@ #define __NR_pidfd_getfd (__NR_Linux + 438) #define __NR_faccessat2 (__NR_Linux + 439) #define __NR_process_madvise (__NR_Linux + 440) +#define __NR_epoll_pwait2 (__NR_Linux + 441) #endif /* _ASM_MIPS_UNISTD_N64_H */ diff --git a/linux-headers/asm-mips/unistd_o32.h b/linux-headers/asm-mips/unistd_o32.h index 5222a0dd50..ca6a7e5c0b 100644 --- a/linux-headers/asm-mips/unistd_o32.h +++ b/linux-headers/asm-mips/unistd_o32.h @@ -416,6 +416,7 @@ #define __NR_pidfd_getfd (__NR_Linux + 438) #define __NR_faccessat2 (__NR_Linux + 439) #define __NR_process_madvise (__NR_Linux + 440) +#define __NR_epoll_pwait2 (__NR_Linux + 441) #endif /* _ASM_MIPS_UNISTD_O32_H */ diff --git a/linux-headers/asm-powerpc/unistd_32.h b/linux-headers/asm-powerpc/unistd_32.h index 21066a3d5f..4624c90043 100644 --- a/linux-headers/asm-powerpc/unistd_32.h +++ b/linux-headers/asm-powerpc/unistd_32.h @@ -423,6 +423,7 @@ #define __NR_pidfd_getfd 438 #define __NR_faccessat2 439 #define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 #endif /* _ASM_POWERPC_UNISTD_32_H */ diff --git a/linux-headers/asm-powerpc/unistd_64.h b/linux-headers/asm-powerpc/unistd_64.h index c153da29f2..7e851b30bb 100644 --- a/linux-headers/asm-powerpc/unistd_64.h +++ b/linux-headers/asm-powerpc/unistd_64.h @@ -395,6 +395,7 @@ #define __NR_pidfd_getfd 438 #define __NR_faccessat2 439 #define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 #endif /* _ASM_POWERPC_UNISTD_64_H */ diff --git a/linux-headers/asm-s390/unistd_32.h b/linux-headers/asm-s390/unistd_32.h index 3b4f2dda60..c94d2c3a22 100644 --- a/linux-headers/asm-s390/unistd_32.h +++ b/linux-headers/asm-s390/unistd_32.h @@ -413,5 +413,6 @@ #define __NR_pidfd_getfd 438 #define __NR_faccessat2 439 #define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 #endif /* _ASM_S390_UNISTD_32_H */ diff --git a/linux-headers/asm-s390/unistd_64.h b/linux-headers/asm-s390/unistd_64.h index 030a51fa38..984a06b7eb 100644 --- a/linux-headers/asm-s390/unistd_64.h +++ b/linux-headers/asm-s390/unistd_64.h @@ -361,5 +361,6 @@ #define __NR_pidfd_getfd 438 #define __NR_faccessat2 439 #define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 #endif /* _ASM_S390_UNISTD_64_H */ diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 89e5f3d1bb..8e76d3701d 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -12,6 +12,7 @@ #define KVM_PIO_PAGE_OFFSET 1 #define KVM_COALESCED_MMIO_PAGE_OFFSET 2 +#define KVM_DIRTY_LOG_PAGE_OFFSET 64 #define DE_VECTOR 0 #define DB_VECTOR 1 diff --git a/linux-headers/asm-x86/unistd_32.h b/linux-headers/asm-x86/unistd_32.h index cfba368f9d..18fb99dfa2 100644 --- a/linux-headers/asm-x86/unistd_32.h +++ b/linux-headers/asm-x86/unistd_32.h @@ -431,6 +431,7 @@ #define __NR_pidfd_getfd 438 #define __NR_faccessat2 439 #define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 #endif /* _ASM_X86_UNISTD_32_H */ diff --git a/linux-headers/asm-x86/unistd_64.h b/linux-headers/asm-x86/unistd_64.h index 61af725095..bde959328d 100644 --- a/linux-headers/asm-x86/unistd_64.h +++ b/linux-headers/asm-x86/unistd_64.h @@ -353,6 +353,7 @@ #define __NR_pidfd_getfd 438 #define __NR_faccessat2 439 #define __NR_process_madvise 440 +#define __NR_epoll_pwait2 441 #endif /* _ASM_X86_UNISTD_64_H */ diff --git a/linux-headers/asm-x86/unistd_x32.h b/linux-headers/asm-x86/unistd_x32.h index a6890cb1f5..4ff6b17d3b 100644 --- a/linux-headers/asm-x86/unistd_x32.h +++ b/linux-headers/asm-x86/unistd_x32.h @@ -306,6 +306,7 @@ #define __NR_pidfd_getfd (__X32_SYSCALL_BIT + 438) #define __NR_faccessat2 (__X32_SYSCALL_BIT + 439) #define __NR_process_madvise (__X32_SYSCALL_BIT + 440) +#define __NR_epoll_pwait2 (__X32_SYSCALL_BIT + 441) #define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512) #define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513) #define __NR_ioctl (__X32_SYSCALL_BIT + 514) diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 56ce14ad20..020b62a619 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -250,6 +250,7 @@ struct kvm_hyperv_exit { #define KVM_EXIT_ARM_NISV 28 #define KVM_EXIT_X86_RDMSR 29 #define KVM_EXIT_X86_WRMSR 30 +#define KVM_EXIT_DIRTY_RING_FULL 31 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -1053,6 +1054,8 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_X86_USER_SPACE_MSR 188 #define KVM_CAP_X86_MSR_FILTER 189 #define KVM_CAP_ENFORCE_PV_FEATURE_CPUID 190 +#define KVM_CAP_SYS_HYPERV_CPUID 191 +#define KVM_CAP_DIRTY_LOG_RING 192 #ifdef KVM_CAP_IRQ_ROUTING @@ -1511,7 +1514,7 @@ struct kvm_enc_region { /* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT_2 */ #define KVM_CLEAR_DIRTY_LOG _IOWR(KVMIO, 0xc0, struct kvm_clear_dirty_log) -/* Available with KVM_CAP_HYPERV_CPUID */ +/* Available with KVM_CAP_HYPERV_CPUID (vcpu) / KVM_CAP_SYS_HYPERV_CPUID (system) */ #define KVM_GET_SUPPORTED_HV_CPUID _IOWR(KVMIO, 0xc1, struct kvm_cpuid2) /* Available with KVM_CAP_ARM_SVE */ @@ -1557,6 +1560,9 @@ struct kvm_pv_cmd { /* Available with KVM_CAP_X86_MSR_FILTER */ #define KVM_X86_SET_MSR_FILTER _IOW(KVMIO, 0xc6, struct kvm_msr_filter) +/* Available with KVM_CAP_DIRTY_LOG_RING */ +#define KVM_RESET_DIRTY_RINGS _IO(KVMIO, 0xc7) + /* Secure Encrypted Virtualization command */ enum sev_cmd_id { /* Guest initialization commands */ @@ -1710,4 +1716,52 @@ struct kvm_hyperv_eventfd { #define KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (1 << 0) #define KVM_DIRTY_LOG_INITIALLY_SET (1 << 1) +/* + * Arch needs to define the macro after implementing the dirty ring + * feature. KVM_DIRTY_LOG_PAGE_OFFSET should be defined as the + * starting page offset of the dirty ring structures. + */ +#ifndef KVM_DIRTY_LOG_PAGE_OFFSET +#define KVM_DIRTY_LOG_PAGE_OFFSET 0 +#endif + +/* + * KVM dirty GFN flags, defined as: + * + * |---------------+---------------+--------------| + * | bit 1 (reset) | bit 0 (dirty) | Status | + * |---------------+---------------+--------------| + * | 0 | 0 | Invalid GFN | + * | 0 | 1 | Dirty GFN | + * | 1 | X | GFN to reset | + * |---------------+---------------+--------------| + * + * Lifecycle of a dirty GFN goes like: + * + * dirtied harvested reset + * 00 -----------> 01 -------------> 1X -------+ + * ^ | + * | | + * +------------------------------------------+ + * + * The userspace program is only responsible for the 01->1X state + * conversion after harvesting an entry. Also, it must not skip any + * dirty bits, so that dirty bits are always harvested in sequence. + */ +#define KVM_DIRTY_GFN_F_DIRTY BIT(0) +#define KVM_DIRTY_GFN_F_RESET BIT(1) +#define KVM_DIRTY_GFN_F_MASK 0x3 + +/* + * KVM dirty rings should be mapped at KVM_DIRTY_LOG_PAGE_OFFSET of + * per-vcpu mmaped regions as an array of struct kvm_dirty_gfn. The + * size of the gfn buffer is decided by the first argument when + * enabling KVM_CAP_DIRTY_LOG_RING. + */ +struct kvm_dirty_gfn { + __u32 flags; + __u32 slot; + __u64 offset; +}; + #endif /* __LINUX_KVM_H */ diff --git a/linux-headers/linux/userfaultfd.h b/linux-headers/linux/userfaultfd.h index 8d3996eb82..1ba9a9feeb 100644 --- a/linux-headers/linux/userfaultfd.h +++ b/linux-headers/linux/userfaultfd.h @@ -257,4 +257,13 @@ struct uffdio_writeprotect { __u64 mode; }; +/* + * Flags for the userfaultfd(2) system call itself. + */ + +/* + * Create a userfaultfd that can handle page faults only in user mode. + */ +#define UFFD_USER_MODE_ONLY 1 + #endif /* _LINUX_USERFAULTFD_H */ diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index b92dcc4daf..609099e455 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -820,6 +820,7 @@ enum { enum { VFIO_CCW_IO_IRQ_INDEX, VFIO_CCW_CRW_IRQ_INDEX, + VFIO_CCW_REQ_IRQ_INDEX, VFIO_CCW_NUM_IRQS }; diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h index 7523218532..c998860d7b 100644 --- a/linux-headers/linux/vhost.h +++ b/linux-headers/linux/vhost.h @@ -146,4 +146,8 @@ /* Set event fd for config interrupt*/ #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int) + +/* Get the valid iova range */ +#define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \ + struct vhost_vdpa_iova_range) #endif From patchwork Fri Jan 8 16:45:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423881 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=K/0BjQCU; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8Cy3yn7z9sWD for ; Sat, 9 Jan 2021 03:47:42 +1100 (AEDT) Received: from localhost ([::1]:44568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxuvM-0004FF-GF for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 11:47:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuu7-0004B9-2z for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:46:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39411) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxutx-0003k7-RE for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:46:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XP+ch9DopkIwLK8sMynXGI2J3pEPHcTHE3OJ/jRr6Dk=; b=K/0BjQCUhZX2ThNxhckdCiCX63wl/8KcA7puvi0Ln9yU3k2skkPugcaL9yxm5ESW6ftuQ+ mXcol6p+VX145ecFmdCWqIu+EYMYFgoKt8Bva3p4deSB1bAT/cZNxJwjtvh0n9kSoexxXw tV+PtSx4MTpfZwvk8/EgJP0uZScqytA= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-270-US4K6bpPNJyqQS5ydn2k3A-1; Fri, 08 Jan 2021 11:46:09 -0500 X-MC-Unique: US4K6bpPNJyqQS5ydn2k3A-1 Received: by mail-qt1-f200.google.com with SMTP id l7so8685232qth.15 for ; Fri, 08 Jan 2021 08:46:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XP+ch9DopkIwLK8sMynXGI2J3pEPHcTHE3OJ/jRr6Dk=; b=HNVCGlKgmCmeFNNERLdwhJXkXtg+/wYTEQ6VA6k7TqaqGYGqVK48Fghqqj5Utks9yt 53iuPL7Wdm5c/Oh1CrtzIqeNtasv4cUKdAJ9GDx2EAQIN7lrg84nW5Ce6bWJtf8/S7LP sjSg+/9oMPxQ3jvKFhQrmm08CqmvTZCXRZIwFdi/Yb50oTWQkGPY701XCHMYcqdybsfB IwnYLhdpoucj7lwkVdUrpDIrq1pgDR2E0GL7QkCY78aKDE92wQdCu7iE1QqMNgIF+UJT Walyy353JpGo3UUhzNYxmBrTTi/rdnPryJv719lamy1uxHvPwqgknqIi+7fdM02M9Tii HX8w== X-Gm-Message-State: AOAM532TOVWl16rcQ1CShlGWQa3ekZVsjJ+LHIjVUkkoQLRpxJ9i4Wb0 BYgHhKVeBb3fywbOe18eiyc97Mt/tYG46gymzcMPmTuTrMLhm+UXH/nRAYEr4OGuQkGaGq1mCQC 2m16ZPP7kX8ZsF6rlZiKi96qHkNItRpKhPscvwDi8k/64npvl6dWh1P621Nypa+fZ X-Received: by 2002:ac8:5514:: with SMTP id j20mr4281769qtq.387.1610124367758; Fri, 08 Jan 2021 08:46:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwI1GG2Qasb0h7rpNV4ftzW2DJkpTgpnFIuR+/eDfgdl2wS6yeUBs226Q7pywrUIm/89Og55g== X-Received: by 2002:ac8:5514:: with SMTP id j20mr4281745qtq.387.1610124367463; Fri, 08 Jan 2021 08:46:07 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id c139sm5067437qke.24.2021.01.08.08.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:46:06 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 03/13] memory: Introduce log_sync_global() to memory listener Date: Fri, 8 Jan 2021 11:45:51 -0500 Message-Id: <20210108164601.406146-4-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108164601.406146-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Some of the memory listener may want to do log synchronization without being able to specify a range of memory to sync but always globally. Such a memory listener should provide this new method instead of the log_sync() method. Obviously we can also achieve similar thing when we put the global sync logic into a log_sync() handler. However that's not efficient enough because otherwise memory_global_dirty_log_sync() may do the global sync N times, where N is the number of flat ranges in the address space. Make this new method be exclusive to log_sync(). Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- include/exec/memory.h | 12 ++++++++++++ softmmu/memory.c | 33 +++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 521d9901d7..f80b68f1e3 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -610,6 +610,18 @@ struct MemoryListener { */ void (*log_sync)(MemoryListener *listener, MemoryRegionSection *section); + /** + * @log_sync_global: + * + * This is the global version of @log_sync when the listener does + * not have a way to synchronize the log with finer granularity. + * When the listener registers with @log_sync_global defined, then + * its @log_sync must be NULL. Vice versa. + * + * @listener: The #MemoryListener. + */ + void (*log_sync_global)(MemoryListener *listener); + /** * @log_clear: * diff --git a/softmmu/memory.c b/softmmu/memory.c index 333e1ed7b0..824abe3c7a 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2052,6 +2052,10 @@ void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, memory_region_get_dirty_log_mask(mr)); } +/* + * If memory region `mr' is NULL, do global sync. Otherwise, sync + * dirty bitmap for the specified memory region. + */ static void memory_region_sync_dirty_bitmap(MemoryRegion *mr) { MemoryListener *listener; @@ -2065,18 +2069,24 @@ static void memory_region_sync_dirty_bitmap(MemoryRegion *mr) * address space once. */ QTAILQ_FOREACH(listener, &memory_listeners, link) { - if (!listener->log_sync) { - continue; - } - as = listener->address_space; - view = address_space_get_flatview(as); - FOR_EACH_FLAT_RANGE(fr, view) { - if (fr->dirty_log_mask && (!mr || fr->mr == mr)) { - MemoryRegionSection mrs = section_from_flat_range(fr, view); - listener->log_sync(listener, &mrs); + if (listener->log_sync) { + as = listener->address_space; + view = address_space_get_flatview(as); + FOR_EACH_FLAT_RANGE(fr, view) { + if (fr->dirty_log_mask && (!mr || fr->mr == mr)) { + MemoryRegionSection mrs = section_from_flat_range(fr, view); + listener->log_sync(listener, &mrs); + } } + flatview_unref(view); + } else if (listener->log_sync_global) { + /* + * No matter whether MR is specified, what we can do here + * is to do a global sync, because we are not capable to + * sync in a finer granularity. + */ + listener->log_sync_global(listener); } - flatview_unref(view); } } @@ -2764,6 +2774,9 @@ void memory_listener_register(MemoryListener *listener, AddressSpace *as) { MemoryListener *other = NULL; + /* Only one of them can be defined for a listener */ + assert(!(listener->log_sync && listener->log_sync_global)); + listener->address_space = as; if (QTAILQ_EMPTY(&memory_listeners) || listener->priority >= QTAILQ_LAST(&memory_listeners)->priority) { From patchwork Fri Jan 8 16:50:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=do3V4h2n; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8cl3MbKz9sWl for ; Sat, 9 Jan 2021 04:05:43 +1100 (AEDT) Received: from localhost ([::1]:46790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxvCh-0001KD-Sk for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 12:05:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyX-00083q-1r for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:50:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyV-0005Qv-C2 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:50:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lmY2JhNZLUnqHP6NOYqPtDSEUE0yShWpehx9qX7laNk=; b=do3V4h2nn3ddqiuppOyN6zmcjcBxKnI2WbgVuG2MLU60Fk1iYKWTvOe6qHAPl1l4/8FJAD k0G2cMKS2ze0KsCTwQUHOSnXEuIfB7OXncwv3DAZDoOP68xbrF6sS+Gyf+Cg6/q5oXJlSH pzJYKDjTintBagxybUWU3LEs2uycO4g= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-EgtPSOZTOLOmUz9Si841bQ-1; Fri, 08 Jan 2021 11:50:53 -0500 X-MC-Unique: EgtPSOZTOLOmUz9Si841bQ-1 Received: by mail-qk1-f199.google.com with SMTP id y187so9714556qke.20 for ; Fri, 08 Jan 2021 08:50:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lmY2JhNZLUnqHP6NOYqPtDSEUE0yShWpehx9qX7laNk=; b=ISt7+DkRWyW5s3u2Kwk9LezEfcx9t3TxFOwzZ+vle3YGHe1wOjPdHOttKGTuEH075F 6jvvmE2CZADj/hG1krdt3B33CUaM5jKVsvfT0CnPStlMshMPLpBthMD5YFtXhcGAGMM9 gqxeLWBz6pThfuAdNm2qW2C0SlXefiH3Wn8ykAPB3UWL3Rf4Lb9A0s+lVfBLFSscQ1Bb rGrPpSPcO2PcXQQmGIw2yK06iCTqds102rCGn4Drp7RE7+TOwXYVvtr8YAPctWzObPdF 2vMkY0d9RGGAbbjJmma5jCc7nDG+Ze5CAqijkkHUu2WBAGiZrknz2ZORrrs2y/BBer0u 7Qxg== X-Gm-Message-State: AOAM532LfJ2xLS1L9L5tDKm4BCK2mlumznvmhzUQZcLocKnkU49JTUhr aAeTG+LUnqj7rPcRJmuNV+B5LRG0Ldc8fYUBqpt/vcLuJ/WYku4WDRW9SSbNm94c6Wi7AJ1PrZN eEqsV8m32dgnhZxH87XuyMptCyrHUkKeqUdCfWd88kxbzKk2oKTHch5RWMx+kAXAS X-Received: by 2002:a37:6144:: with SMTP id v65mr4998901qkb.222.1610124652515; Fri, 08 Jan 2021 08:50:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAl+Q+j0NU+cIXebbQfJKtY/PvwTUZUVjif2aD5K5P35sw1WC+iLDUnoBOoBS3IU4X6dG6WQ== X-Received: by 2002:a37:6144:: with SMTP id v65mr4998880qkb.222.1610124652218; Fri, 08 Jan 2021 08:50:52 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:50:51 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 04/13] KVM: Fixup kvm_log_clear_one_slot() ioctl return check Date: Fri, 8 Jan 2021 11:50:41 -0500 Message-Id: <20210108165050.406906-1-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108164601.406146-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" kvm_vm_ioctl() handles the errno trick already for ioctl() on returning -1 for errors. Fix this. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 389eaace72..9f779b56ae 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -771,14 +771,13 @@ static int kvm_log_clear_one_slot(KVMSlot *mem, int as_id, uint64_t start, d.num_pages = bmap_npages; d.slot = mem->slot | (as_id << 16); - if (kvm_vm_ioctl(s, KVM_CLEAR_DIRTY_LOG, &d) == -1) { - ret = -errno; + ret = kvm_vm_ioctl(s, KVM_CLEAR_DIRTY_LOG, &d); + if (ret) { error_report("%s: KVM_CLEAR_DIRTY_LOG failed, slot=%d, " "start=0x%"PRIx64", size=0x%"PRIx32", errno=%d", __func__, d.slot, (uint64_t)d.first_page, (uint32_t)d.num_pages, ret); } else { - ret = 0; trace_kvm_clear_dirty_log(d.slot, d.first_page, d.num_pages); } From patchwork Fri Jan 8 16:50:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FFj4VMT3; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8MZ5SHTz9sW8 for ; Sat, 9 Jan 2021 03:54:18 +1100 (AEDT) Received: from localhost ([::1]:55826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxv1k-0000wf-OI for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 11:54:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyZ-00089L-2J for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:50:59 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyW-0005Ru-Ve for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:50:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dNNUkgCHDqnn4h+zLY4Ywf90DjPhnZqB9vTnYirewJM=; b=FFj4VMT3GOijda5YWlZr1YZFQL7gtnsnMP4trF4nD0n4kT395aVr4q7miDaA55IYGwfoNv E9YKim/scoIYNjgK0VDNTae4B5giNhP7lDZlfGPeGod2oWKAm/3fLS/3SZtm/2L3vvSojJ b1n703VE6z9HR1YsWuRF5+NXjJMIOBY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-Jp_IRJFlNzSh9UJoGqT4nw-1; Fri, 08 Jan 2021 11:50:54 -0500 X-MC-Unique: Jp_IRJFlNzSh9UJoGqT4nw-1 Received: by mail-qv1-f69.google.com with SMTP id x17so285014qvo.23 for ; Fri, 08 Jan 2021 08:50:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dNNUkgCHDqnn4h+zLY4Ywf90DjPhnZqB9vTnYirewJM=; b=qjKc+cFRRuI6uHqV26xZrP9EGQbcoQKo00bwiOadgBJ2dtc/Cfi/MwN3UKAj9Uaojq 03HH/vPhwWjcMXa8qG+6OCGOUVYwLJuJlmVwDyREDV7QvOviWX9MZ4qY+8qCEJVtO9Pn dQmw6gdXWMiuhc8Iu7OeO5nJP4mV0Zt4dOVkGTb6vp/SciIAIKzHN9ed8SOqNvBK+3aL auwr27A4SaloPCgoI1l7pBJqcg+2rg3tzYM1umXjLTRFdt3FySmPz35S1RcvInUdfUc9 VtokpxSPWYHuuj/tG5yh4WNJGMr4oTJ/DqK4IrHlc4RWtxnNDCRkKcVSySQfMrPOVDcm wXSQ== X-Gm-Message-State: AOAM533nZYNKP4DRxk5wda4fGEK3ZokP6pf5nZcClXtaxtN8H3+HReKT rW+SHw1YkyEooOi1FmPoe7DRPJUImFQeL5gUldfQqAHtaxxEQ/6AQYgExzcQ1dc46+doFMXd9oF 2Ppn3aclUJDqsfD9tWIvym8E/EvqCdAgA0eR9fkdpp3DUAoUZXR5/i5hnQqA6TBqf X-Received: by 2002:a05:620a:2104:: with SMTP id l4mr4553764qkl.35.1610124653685; Fri, 08 Jan 2021 08:50:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4w1MHyBEMqd7FSrVWQcgVmIgieMmLk7edhfAwuIK5INpfFevdLeQXdjMC4nzrAuaPZnJF/Q== X-Received: by 2002:a05:620a:2104:: with SMTP id l4mr4553740qkl.35.1610124653416; Fri, 08 Jan 2021 08:50:53 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:50:52 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 05/13] KVM: Use a big lock to replace per-kml slots_lock Date: Fri, 8 Jan 2021 11:50:42 -0500 Message-Id: <20210108165050.406906-2-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Per-kml slots_lock will bring some trouble if we want to take all slots_lock of all the KMLs, especially when we're in a context that we could have taken some of the KML slots_lock, then we even need to figure out what we've taken and what we need to take. Make this simple by merging all KML slots_lock into a single slots lock. Per-kml slots_lock isn't anything that helpful anyway - so far only x86 has two address spaces (so, two slots_locks). All the rest archs will be having one address space always, which means there's actually one slots_lock so it will be the same as before. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 32 +++++++++++++++++--------------- include/sysemu/kvm_int.h | 2 -- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 9f779b56ae..d891a22a3b 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -176,8 +176,10 @@ typedef struct KVMResampleFd KVMResampleFd; static QLIST_HEAD(, KVMResampleFd) kvm_resample_fd_list = QLIST_HEAD_INITIALIZER(kvm_resample_fd_list); -#define kvm_slots_lock(kml) qemu_mutex_lock(&(kml)->slots_lock) -#define kvm_slots_unlock(kml) qemu_mutex_unlock(&(kml)->slots_lock) +static QemuMutex kml_slots_lock; + +#define kvm_slots_lock() qemu_mutex_lock(&kml_slots_lock) +#define kvm_slots_unlock() qemu_mutex_unlock(&kml_slots_lock) static inline void kvm_resample_fd_remove(int gsi) { @@ -263,9 +265,9 @@ bool kvm_has_free_slot(MachineState *ms) bool result; KVMMemoryListener *kml = &s->memory_listener; - kvm_slots_lock(kml); + kvm_slots_lock(); result = !!kvm_get_free_slot(kml); - kvm_slots_unlock(kml); + kvm_slots_unlock(); return result; } @@ -331,7 +333,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram, KVMMemoryListener *kml = &s->memory_listener; int i, ret = 0; - kvm_slots_lock(kml); + kvm_slots_lock(); for (i = 0; i < s->nr_slots; i++) { KVMSlot *mem = &kml->slots[i]; @@ -341,7 +343,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram, break; } } - kvm_slots_unlock(kml); + kvm_slots_unlock(); return ret; } @@ -537,7 +539,7 @@ static int kvm_section_update_flags(KVMMemoryListener *kml, return 0; } - kvm_slots_lock(kml); + kvm_slots_lock(); while (size && !ret) { slot_size = MIN(kvm_max_slot_size, size); @@ -553,7 +555,7 @@ static int kvm_section_update_flags(KVMMemoryListener *kml, } out: - kvm_slots_unlock(kml); + kvm_slots_unlock(); return ret; } @@ -826,7 +828,7 @@ static int kvm_physical_log_clear(KVMMemoryListener *kml, return ret; } - kvm_slots_lock(kml); + kvm_slots_lock(); for (i = 0; i < s->nr_slots; i++) { mem = &kml->slots[i]; @@ -852,7 +854,7 @@ static int kvm_physical_log_clear(KVMMemoryListener *kml, } } - kvm_slots_unlock(kml); + kvm_slots_unlock(); return ret; } @@ -1157,7 +1159,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram = memory_region_get_ram_ptr(mr) + section->offset_within_region + (start_addr - section->offset_within_address_space); - kvm_slots_lock(kml); + kvm_slots_lock(); if (!add) { do { @@ -1215,7 +1217,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, } while (size); out: - kvm_slots_unlock(kml); + kvm_slots_unlock(); } static void kvm_region_add(MemoryListener *listener, @@ -1242,9 +1244,9 @@ static void kvm_log_sync(MemoryListener *listener, KVMMemoryListener *kml = container_of(listener, KVMMemoryListener, listener); int r; - kvm_slots_lock(kml); + kvm_slots_lock(); r = kvm_physical_sync_dirty_bitmap(kml, section); - kvm_slots_unlock(kml); + kvm_slots_unlock(); if (r < 0) { abort(); } @@ -1344,7 +1346,7 @@ void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml, { int i; - qemu_mutex_init(&kml->slots_lock); + qemu_mutex_init(&kml_slots_lock); kml->slots = g_malloc0(s->nr_slots * sizeof(KVMSlot)); kml->as_id = as_id; diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 65740806da..f3d9eed750 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -27,8 +27,6 @@ typedef struct KVMSlot typedef struct KVMMemoryListener { MemoryListener listener; - /* Protects the slots and all inside them */ - QemuMutex slots_lock; KVMSlot *slots; int as_id; } KVMMemoryListener; From patchwork Fri Jan 8 16:50:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TYZifMKU; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8Ll3Zrkz9sW8 for ; Sat, 9 Jan 2021 03:53:35 +1100 (AEDT) Received: from localhost ([::1]:54536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxv12-0000JB-8V for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 11:53:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyc-0008Gl-1u for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45063) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyZ-0005TA-Vt for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=onsr8KF3PBLI6UDXEBSCNCjeHrVYzpBaCySkBptySp0=; b=TYZifMKUw5DqoqQZXm8LxND8fASbSq6cXQ2yjwtClMJrck2cSM/T+VNkvgkzn67DZbEwFP /iW1fVj2ZMfCWCKE3zazp0Ri7IIZSGdIdWVPWllZNsh0SlZS7lfofjlazUue/31QU5uIXX phhjomiOoLIKRAlCovbTYE9sHCKzpME= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-ubVM2ronMLyXCMSZ2RWGOQ-1; Fri, 08 Jan 2021 11:50:55 -0500 X-MC-Unique: ubVM2ronMLyXCMSZ2RWGOQ-1 Received: by mail-qt1-f200.google.com with SMTP id p20so8727833qtq.3 for ; Fri, 08 Jan 2021 08:50:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=onsr8KF3PBLI6UDXEBSCNCjeHrVYzpBaCySkBptySp0=; b=VJSCObphDOvHvvipzyelxOBrGLLOvQI3RdGVzHL5jsAPwQPpDn756innOgPxnt65Lf dS9laQu50qQdF9exQdZw8IEPIX1mAN9k6+5cglujkc1lPxGBazi49WpoJJuiIc18XQsi ALh7jEgy1XmOW4t0XbA1BRszPv/DM6L3xgDLjbquELFBkNIVPormSDvWDHZwr8/BSKPZ 6wjhXE4ClUkO/3w0xqZbtVki9hSHTZ/OMCalwAybsHDaucDdZZBD5g8IIw02fRiT7lD1 dsyHyK9pgYTH+EUJcrjEH5yEfy6Tlli+1iC/fGDpkom54YV34zHx620S7LcRJsUc3qbW dzCw== X-Gm-Message-State: AOAM531AtAQM9OYmQ89FDmgxa/EJ6QlpLcCW2daymZinjh8zi4Qh5en1 h50CbjdCaHAsZIyWCiFCaUZOvNKy5zybHHGjYiZMgX+K+wDUMIM9gBt7su1kaHCnvSvJzWwMASt EfQmKtHqrEkAdXnpo691kLJwmgWTcKhWvMdzBCS+oIsjm09MkvEtFtHzip7Kv4teC X-Received: by 2002:a05:620a:2108:: with SMTP id l8mr1434159qkl.232.1610124655014; Fri, 08 Jan 2021 08:50:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJz5c+wYJ6RxuJPNtyka4TXp/Jp51WCVbd3Mhk+xaJi8VLT5/39ayDXXsM1ojp+owzJa4N09Og== X-Received: by 2002:a05:620a:2108:: with SMTP id l8mr1434134qkl.232.1610124654741; Fri, 08 Jan 2021 08:50:54 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:50:53 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 06/13] KVM: Create the KVMSlot dirty bitmap on flag changes Date: Fri, 8 Jan 2021 11:50:43 -0500 Message-Id: <20210108165050.406906-3-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Previously we have two places that will create the per KVMSlot dirty bitmap: 1. When a newly created KVMSlot has dirty logging enabled, 2. When the first log_sync() happens for a memory slot. The 2nd case is lazy-init, while the 1st case is not (which is a fix of what the 2nd case missed). To do explicit initialization of dirty bitmaps, what we're missing is to create the dirty bitmap when the slot changed from not-dirty-track to dirty-track. Do that in kvm_slot_update_flags(). With that, we can safely remove the 2nd lazy-init. This change will be needed for kvm dirty ring because kvm dirty ring does not use the log_sync() interface at all. Also move all the pre-checks into kvm_slot_init_dirty_bitmap(). Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d891a22a3b..445ce1b177 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -181,6 +181,8 @@ static QemuMutex kml_slots_lock; #define kvm_slots_lock() qemu_mutex_lock(&kml_slots_lock) #define kvm_slots_unlock() qemu_mutex_unlock(&kml_slots_lock) +static void kvm_slot_init_dirty_bitmap(KVMSlot *mem); + static inline void kvm_resample_fd_remove(int gsi) { KVMResampleFd *rfd; @@ -524,6 +526,7 @@ static int kvm_slot_update_flags(KVMMemoryListener *kml, KVMSlot *mem, return 0; } + kvm_slot_init_dirty_bitmap(mem); return kvm_set_user_memory_region(kml, mem, false); } @@ -608,8 +611,12 @@ static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) /* Allocate the dirty bitmap for a slot */ -static void kvm_memslot_init_dirty_bitmap(KVMSlot *mem) +static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) { + if (!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) || mem->dirty_bmap) { + return; + } + /* * XXX bad kernel interface alert * For dirty bitmap, kernel allocates array of size aligned to @@ -660,11 +667,6 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, goto out; } - if (!mem->dirty_bmap) { - /* Allocate on the first log_sync, once and for all */ - kvm_memslot_init_dirty_bitmap(mem); - } - d.dirty_bitmap = mem->dirty_bmap; d.slot = mem->slot | (kml->as_id << 16); if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) { @@ -1197,14 +1199,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->start_addr = start_addr; mem->ram = ram; mem->flags = kvm_mem_flags(mr); - - if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { - /* - * Reallocate the bmap; it means it doesn't disappear in - * middle of a migrate. - */ - kvm_memslot_init_dirty_bitmap(mem); - } + kvm_slot_init_dirty_bitmap(mem); err = kvm_set_user_memory_region(kml, mem, true); if (err) { fprintf(stderr, "%s: error registering slot: %s\n", __func__, From patchwork Fri Jan 8 16:50:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=X5WNwxmZ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8MJ6Zsyz9sW8 for ; Sat, 9 Jan 2021 03:54:04 +1100 (AEDT) Received: from localhost ([::1]:55790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxv1W-0000vf-TY for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 11:54:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyd-0008Gr-85 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuya-0005TC-0b for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DPi+d1XqVd+CjlStCrdNo1ZBhL5tTHGRRSkr6Dc1gz0=; b=X5WNwxmZddbl3xtOnkcPuloRyKzRCY6wQfhJbqKUK/XlkNf4Y1dPoTEf3pdP3QuHxr4hou +gc1LwKVW6No97J7wVDaEG0mMBKCvrIpTJrCj+DCbwcNBlwj9avdV3JO9YXepEQveLbOPq dt9qIbrplh7Eh4qLEPNRYrn0oToOLvI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-297-XAxUC7zJMBq8fYg6zAGkXw-1; Fri, 08 Jan 2021 11:50:57 -0500 X-MC-Unique: XAxUC7zJMBq8fYg6zAGkXw-1 Received: by mail-qk1-f200.google.com with SMTP id f27so9752445qkh.0 for ; Fri, 08 Jan 2021 08:50:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DPi+d1XqVd+CjlStCrdNo1ZBhL5tTHGRRSkr6Dc1gz0=; b=Ol4XfGYKziyQ/I6e+g5SoAjMVFGGmnh5ckwVwdDZsi9dlxdSI916Eu5uJxhZQk5AKF qu3a++caqSkLfyewoWJjRbHICGLoPvCaoKGqn02S6knXHbCbGWkTM09ND/qhjZ92uN7B JMr24AmmsxgXiMXFrPxNig7BBu3uUpZGVAQFyhN543o9qPJZIFmknvt92SL+g33yJCPW 7Dhc/JPacL0rzCgntecNPKnXc/vUV1UlHdbW/ytgNuEV2nXWytyhRBZ7Ni1QaKJOOlmv TxzbXflxMqaH0ndGDi6hJemyh1BJYQ7nSie0aBpvEL5HawYtV81by88IFHHWx0g8xE/B WJLA== X-Gm-Message-State: AOAM530zl7MTj9efW3f63d/wFokFCTt8jhJZKOh3d+2aI9aoHJh+EdqN F45Gmp4YzvYMvj0pDmo9z2Z0M/MR0tOS2uNo/6VFnqZXv/3GQ4HnIJkqwCProjyMOmrakVrPfSW Oa6Pf74vj1Ap7jyJP4N+G5BhE/7OIpoPtsz9qgAUh0zCO1jKWuvy+FBWPM76JCIdA X-Received: by 2002:a37:9fc6:: with SMTP id i189mr4595338qke.41.1610124656301; Fri, 08 Jan 2021 08:50:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOhqSzEDkNERgr/nlQVVxUV2Mo6D5puD3vqjetC7BTmpZcw+XnKpqHLDqpW0zINXQdoAj0Cw== X-Received: by 2002:a37:9fc6:: with SMTP id i189mr4595306qke.41.1610124655987; Fri, 08 Jan 2021 08:50:55 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:50:55 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 07/13] KVM: Provide helper to get kvm dirty log Date: Fri, 8 Jan 2021 11:50:44 -0500 Message-Id: <20210108165050.406906-4-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Provide a helper kvm_slot_get_dirty_log() to make the function kvm_physical_sync_dirty_bitmap() clearer. We can even cache the as_id into KVMSlot when it is created, so that we don't even need to pass it down every time. Since at it, remove return value of kvm_physical_sync_dirty_bitmap() because it should never fail. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 42 +++++++++++++++++++++------------------- include/sysemu/kvm_int.h | 2 ++ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 445ce1b177..aaa2e1acaa 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -635,6 +635,21 @@ static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) mem->dirty_bmap = g_malloc0(bitmap_size); } +/* Sync dirty bitmap from kernel to KVMSlot.dirty_bmap */ +static void kvm_slot_get_dirty_log(KVMState *s, KVMSlot *slot) +{ + struct kvm_dirty_log d = {}; + int ret; + + d.dirty_bitmap = slot->dirty_bmap; + d.slot = slot->slot | (slot->as_id << 16); + ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d); + if (ret) { + error_report_once("%s: KVM_GET_DIRTY_LOG failed with %d", + __func__, ret); + } +} + /** * kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * @@ -646,15 +661,13 @@ static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) * @kml: the KVM memory listener object * @section: the memory section to sync the dirty bitmap with */ -static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, - MemoryRegionSection *section) +static void kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, + MemoryRegionSection *section) { KVMState *s = kvm_state; - struct kvm_dirty_log d = {}; KVMSlot *mem; hwaddr start_addr, size; hwaddr slot_size, slot_offset = 0; - int ret = 0; size = kvm_align_section(section, &start_addr); while (size) { @@ -664,27 +677,19 @@ static int kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, mem = kvm_lookup_matching_slot(kml, start_addr, slot_size); if (!mem) { /* We don't have a slot if we want to trap every access. */ - goto out; + return; } - d.dirty_bitmap = mem->dirty_bmap; - d.slot = mem->slot | (kml->as_id << 16); - if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) { - DPRINTF("ioctl failed %d\n", errno); - ret = -1; - goto out; - } + kvm_slot_get_dirty_log(s, mem); subsection.offset_within_region += slot_offset; subsection.size = int128_make64(slot_size); - kvm_get_dirty_pages_log_range(&subsection, d.dirty_bitmap); + kvm_get_dirty_pages_log_range(&subsection, mem->dirty_bmap); slot_offset += slot_size; start_addr += slot_size; size -= slot_size; } -out: - return ret; } /* Alignment requirement for KVM_CLEAR_DIRTY_LOG - 64 pages */ @@ -1195,6 +1200,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, do { slot_size = MIN(kvm_max_slot_size, size); mem = kvm_alloc_slot(kml); + mem->as_id = kml->as_id; mem->memory_size = slot_size; mem->start_addr = start_addr; mem->ram = ram; @@ -1237,14 +1243,10 @@ static void kvm_log_sync(MemoryListener *listener, MemoryRegionSection *section) { KVMMemoryListener *kml = container_of(listener, KVMMemoryListener, listener); - int r; kvm_slots_lock(); - r = kvm_physical_sync_dirty_bitmap(kml, section); + kvm_physical_sync_dirty_bitmap(kml, section); kvm_slots_unlock(); - if (r < 0) { - abort(); - } } static void kvm_log_clear(MemoryListener *listener, diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index f3d9eed750..a9c327427f 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -23,6 +23,8 @@ typedef struct KVMSlot int old_flags; /* Dirty bitmap cache for the slot */ unsigned long *dirty_bmap; + /* Cache of the address space ID */ + int as_id; } KVMSlot; typedef struct KVMMemoryListener { From patchwork Fri Jan 8 16:50:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RMg4C1bI; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8SK6Kv1z9sW8 for ; Sat, 9 Jan 2021 03:58:25 +1100 (AEDT) Received: from localhost ([::1]:36004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxv5j-0004hg-SH for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 11:58:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyd-0008H3-Im for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51495) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyb-0005Vv-An for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KVN8EDR1yzv1Ly9rwho3gPFm9pICzuqAABenHkcfGhM=; b=RMg4C1bIRpFEMLP+3zvsOtuwa/M2x0uoHYNlGzooN+C0Nxonh7Z+Rl/bHJ1JRu0zJ2DXyV vv2JnrCOBtJZi601lrUDkBUMS2YOU2Mpsjd4nYfmZBD65NQnx6gFVqIssZLG2LWAOg0Byh FZgAgqE24ElJ6uCJnNsNe6pQUidT6H4= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-80-tQIYI261OrKO2oNkiZjBpg-1; Fri, 08 Jan 2021 11:50:58 -0500 X-MC-Unique: tQIYI261OrKO2oNkiZjBpg-1 Received: by mail-qk1-f200.google.com with SMTP id s66so9723024qkh.10 for ; Fri, 08 Jan 2021 08:50:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KVN8EDR1yzv1Ly9rwho3gPFm9pICzuqAABenHkcfGhM=; b=eKoumVlVA02WiybbIoXqmgtuKnAKgNAfNFj5C3dpKCN3yW9LKA2VgGLqHKGKpStqsR LffU17u5CSI3ntDLm0TGzJAcL430hRPlMCF+DshiUXn7jGVxKe0n4YfT7vhQiPg6FdcI +DH2gIx4HWdl8VozceAK64p1Vk9UY45aTPMlCFSkPkoGADuAK1gf+2LBqDoRq7/6xRXe hyWCSTwPD6LfiDh5T+sDDry0xxpwS256FqxTEsNp0BspiuAbOK3c8aCS27VGTbSC6JX5 H5Q4fo0EdSbhMq4n5/ldvr5h+NBGg3ZbJM3EfmtIayiSaPxzRoHxtpVftHTdSz+ZQVB/ 8SHQ== X-Gm-Message-State: AOAM5324qyJfzOSO5QLfWIZBZNBFm2aKcnyW6IsxIN5RIC8epDDo8Fa5 V+BrBBkCidOsKbyLllZI8R2vxgAlUAYoTiPB0ZtpH+WYcb/bynrwBSbs3yWKSN7NLHXdvR25+/x AoSr34Y1Wn/+t/0F8aGe2HiqZUbaVWibmByGk35IBN3s66/O7+P9WakjoEv+R+7Fa X-Received: by 2002:a05:620a:218e:: with SMTP id g14mr4916426qka.243.1610124657564; Fri, 08 Jan 2021 08:50:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsEE4IAlsq5r01vbYsy04xJkS8F/Je74mCrGMYGl82+ldSYb7V8VtNLVqyxp9TQUo+VHYncQ== X-Received: by 2002:a05:620a:218e:: with SMTP id g14mr4916405qka.243.1610124657274; Fri, 08 Jan 2021 08:50:57 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:50:56 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 08/13] KVM: Provide helper to sync dirty bitmap from slot to ramblock Date: Fri, 8 Jan 2021 11:50:45 -0500 Message-Id: <20210108165050.406906-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" kvm_physical_sync_dirty_bitmap() calculates the ramblock offset in an awkward way from the MemoryRegionSection that passed in from the caller. The truth is for each KVMSlot the ramblock offset never change for the lifecycle. Cache the ramblock offset for each KVMSlot into the structure when the KVMSlot is created. With that, we can further simplify kvm_physical_sync_dirty_bitmap() with a helper to sync KVMSlot dirty bitmap to the ramblock dirty bitmap of a specific KVMSlot. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 37 +++++++++++++++++-------------------- include/sysemu/kvm_int.h | 2 ++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index aaa2e1acaa..c7c7627c82 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -597,15 +597,12 @@ static void kvm_log_stop(MemoryListener *listener, } /* get kvm's dirty pages bitmap and update qemu's */ -static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, - unsigned long *bitmap) +static void kvm_slot_sync_dirty_pages(KVMSlot *slot) { - ram_addr_t start = section->offset_within_region + - memory_region_get_ram_addr(section->mr); - ram_addr_t pages = int128_get64(section->size) / qemu_real_host_page_size; + ram_addr_t start = slot->ram_start_offset; + ram_addr_t pages = slot->memory_size / qemu_real_host_page_size; - cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages); - return 0; + cpu_physical_memory_set_dirty_lebitmap(slot->dirty_bmap, start, pages); } #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) @@ -667,12 +664,10 @@ static void kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, KVMState *s = kvm_state; KVMSlot *mem; hwaddr start_addr, size; - hwaddr slot_size, slot_offset = 0; + hwaddr slot_size; size = kvm_align_section(section, &start_addr); while (size) { - MemoryRegionSection subsection = *section; - slot_size = MIN(kvm_max_slot_size, size); mem = kvm_lookup_matching_slot(kml, start_addr, slot_size); if (!mem) { @@ -681,12 +676,7 @@ static void kvm_physical_sync_dirty_bitmap(KVMMemoryListener *kml, } kvm_slot_get_dirty_log(s, mem); - - subsection.offset_within_region += slot_offset; - subsection.size = int128_make64(slot_size); - kvm_get_dirty_pages_log_range(&subsection, mem->dirty_bmap); - - slot_offset += slot_size; + kvm_slot_sync_dirty_pages(mem); start_addr += slot_size; size -= slot_size; } @@ -1144,7 +1134,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, int err; MemoryRegion *mr = section->mr; bool writeable = !mr->readonly && !mr->rom_device; - hwaddr start_addr, size, slot_size; + hwaddr start_addr, size, slot_size, mr_offset; + ram_addr_t ram_start_offset; void *ram; if (!memory_region_is_ram(mr)) { @@ -1162,9 +1153,13 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, return; } - /* use aligned delta to align the ram address */ - ram = memory_region_get_ram_ptr(mr) + section->offset_within_region + - (start_addr - section->offset_within_address_space); + /* The offset of the kvmslot within the memory region */ + mr_offset = section->offset_within_region + start_addr - + section->offset_within_address_space; + + /* use aligned delta to align the ram address and offset */ + ram = memory_region_get_ram_ptr(mr) + mr_offset; + ram_start_offset = memory_region_get_ram_addr(mr) + mr_offset; kvm_slots_lock(); @@ -1203,6 +1198,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, mem->as_id = kml->as_id; mem->memory_size = slot_size; mem->start_addr = start_addr; + mem->ram_start_offset = ram_start_offset; mem->ram = ram; mem->flags = kvm_mem_flags(mr); kvm_slot_init_dirty_bitmap(mem); @@ -1213,6 +1209,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, abort(); } start_addr += slot_size; + ram_start_offset += slot_size; ram += slot_size; size -= slot_size; } while (size); diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index a9c327427f..e0afdd02fd 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -25,6 +25,8 @@ typedef struct KVMSlot unsigned long *dirty_bmap; /* Cache of the address space ID */ int as_id; + /* Cache of the offset in ram address space */ + ram_addr_t ram_start_offset; } KVMSlot; typedef struct KVMMemoryListener { From patchwork Fri Jan 8 16:50:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ELDn7awr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8hm60vPz9sW8 for ; Sat, 9 Jan 2021 04:09:12 +1100 (AEDT) Received: from localhost ([::1]:54584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxvGA-0004t4-Rn for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 12:09:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyf-0008Ki-75 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39298) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyd-0005Zb-0y for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tdRYwi1n/ySy5+jKgo9vf500HBDzPxH/huLrT21cayg=; b=ELDn7awrvCd28ICAtejNtLjaqwPhkpKnsoKpz5h8+Z0ReI1mJ036zoSRv2C8Y4uohIdHjg 9Evq/FNbW/NOpBEOiXIZ5GWXHRigRcaB1Yi7b4Po3L070rRHJTRJGooV/DDjgRLtqykWKk ASUfW1K6Ju3vyA6LmohjhJW9vpWQPI0= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-416-JlSdfmCEOZ6VLlLH8pkO2Q-1; Fri, 08 Jan 2021 11:50:59 -0500 X-MC-Unique: JlSdfmCEOZ6VLlLH8pkO2Q-1 Received: by mail-qv1-f69.google.com with SMTP id l3so8641242qvr.10 for ; Fri, 08 Jan 2021 08:50:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tdRYwi1n/ySy5+jKgo9vf500HBDzPxH/huLrT21cayg=; b=AHC9zy1pdpBPMoZX/8SQyJ1eDfCBWlzw32VrbAQROZtXH3eoSglnjPfdENu+OgAeYj bC5LKahUP8JHS71ux2vNwIsrS2pf1S7m6Aq5V5ORJk7y4ouCynonpNHE+br/QahrTiDd fx4voaN5ohmYYuUYauNuIPFPT3iokswK88605HQVprVR3+MmqoIQ9VSqTUxJTc5gG2Kj cABtXfJny46OD3UT4ltFWl6Jv5dLWa6U0pBHZxspW4Qc2+qG7+UHqrKSEfT4FdQW1Zyt ywQw5LS+sRzPlXtdV++dnsGjQ4vh+tujAzzPuBIMJ/TYf49yDORJqC/vFaQqiVJpk9JF Y5yA== X-Gm-Message-State: AOAM533simOlaYi+SsG7k8Kif1yqw9B4Qu+hFyXanui4m86Aopa0fFXb foxIpiq9H3AlW2flUdY5Jdy6tsdHBmT3m/3pUvNt2LNjdr07N3O0o6SmT3+9c7hg2w5JYMyaK3z VcqgfKI6E3yG9ZXsx9LXZAfR/+6AWQJv0tQSPlz7aFUCXXb1IxEeXC61h9x97LRpz X-Received: by 2002:ae9:f70a:: with SMTP id s10mr4560245qkg.416.1610124659058; Fri, 08 Jan 2021 08:50:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJys45ZYOwGtpILCQ8dlmTnUyeC/uyQtTs4DFBam1i1MYMR5+WZFOZZbtAqZoDjagxa6XIq6Gw== X-Received: by 2002:ae9:f70a:: with SMTP id s10mr4560207qkg.416.1610124658623; Fri, 08 Jan 2021 08:50:58 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:50:57 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 09/13] KVM: Simplify dirty log sync in kvm_set_phys_mem Date: Fri, 8 Jan 2021 11:50:46 -0500 Message-Id: <20210108165050.406906-6-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" kvm_physical_sync_dirty_bitmap() on the whole section is inaccurate, because the section can be a superset of the memslot that we're working on. The result is that if the section covers multiple kvm memslots, we could be doing the synchronization for multiple times for each kvmslot in the section. With the two helpers that we just introduced, it's very easy to do it right now by calling the helpers. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index c7c7627c82..9cb06ec4d1 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1171,7 +1171,8 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, goto out; } if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { - kvm_physical_sync_dirty_bitmap(kml, section); + kvm_slot_get_dirty_log(kvm_state, mem); + kvm_slot_sync_dirty_pages(mem); } /* unregister the slot */ From patchwork Fri Jan 8 16:50:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HnYOFdpg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8Zj0vwKz9sW8 for ; Sat, 9 Jan 2021 04:03:56 +1100 (AEDT) Received: from localhost ([::1]:44588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxvB2-00009K-Ln for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 12:03:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyg-0008Mc-0j for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyd-0005aI-L4 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/J4bKY4spbyqTa1cxPEZEXtKvTXvco8Td85YHBmvnfU=; b=HnYOFdpgWk/tqFYzNNgtyONM91dyYVJ+K3S9EzqA4gxw7SoLZawvARTLyXP8EqNytojMTz YSNG2SLSNwA8X+oskDsGkuzEHdvO6FZJSvFipg1OsI4gqR4nMqeQK0pJyTBdkcFlWrtYYT OPArg8HBPlcK6EP8Ihr90kB1egRliHU= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-462-ANs1bvCwMfay9hFhu_CIUw-1; Fri, 08 Jan 2021 11:51:01 -0500 X-MC-Unique: ANs1bvCwMfay9hFhu_CIUw-1 Received: by mail-qv1-f70.google.com with SMTP id i20so8647647qvk.18 for ; Fri, 08 Jan 2021 08:51:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/J4bKY4spbyqTa1cxPEZEXtKvTXvco8Td85YHBmvnfU=; b=swraNarywYBR7+5tZfzDTiM9yLNM4emmBDno+vPUV3Vd9QiuA8RBY5fKJRQUUj1CDM Ko+ZuViUQ62uw4rMkQ/w9fgsRa7vdZ51lYtKJy1QoJ0HlIojAHIn4O/DYoHGxCL54hYF SIRGQ4tEJ6XMm9IgLxS0pegei40MPyB+ptNJOJ5ojZh4h8qKHkLPG20AVEgTds5tJJDd m983/+/fWWweBOL6NR5nIOjDKF5xJGit8hsEbhJc2FbDE0zMjaEPUiskgM/CE/H405Z4 L8Cx9Bd5CkhURpCVnLoIW+m/DY1IekdV0rZKomUvZt9FnCBIaBSDneab+EV9LGVZD/xA OoNg== X-Gm-Message-State: AOAM533ojg5UzIp4oyn8cgCKFDrdTefDeaKHgWk41XoIdtt1F07IFV2v bbd08kkI1pPDdYa8gjTsHtYin8GmxqTP8yiMbXtPw4cvF7Z6JMcjZ9nw0LmX7Fod9diL0pFeBuu nLwU1pUs5zBov71L+FIG3Mbh4Km7EtVYHdDhQRhy+UvI8mhhR/VOGmhIQmDvjGiao X-Received: by 2002:a37:9304:: with SMTP id v4mr4716018qkd.137.1610124660293; Fri, 08 Jan 2021 08:51:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLKnwY7W9tRGNjXkhtSxcLpKbKST9IqD0ZakLhQbKNffOLuDhKByIrq5myOvEz4OnhWAZV6A== X-Received: by 2002:a37:9304:: with SMTP id v4mr4715989qkd.137.1610124660046; Fri, 08 Jan 2021 08:51:00 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:50:59 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 10/13] KVM: Cache kvm slot dirty bitmap size Date: Fri, 8 Jan 2021 11:50:47 -0500 Message-Id: <20210108165050.406906-7-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Cache it too because we'll reference it more frequently in the future. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 1 + include/sysemu/kvm_int.h | 1 + 2 files changed, 2 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 9cb06ec4d1..5339de04cf 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -630,6 +630,7 @@ static void kvm_slot_init_dirty_bitmap(KVMSlot *mem) hwaddr bitmap_size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), /*HOST_LONG_BITS*/ 64) / 8; mem->dirty_bmap = g_malloc0(bitmap_size); + mem->dirty_bmap_size = bitmap_size; } /* Sync dirty bitmap from kernel to KVMSlot.dirty_bmap */ diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index e0afdd02fd..7472ddb1a7 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -23,6 +23,7 @@ typedef struct KVMSlot int old_flags; /* Dirty bitmap cache for the slot */ unsigned long *dirty_bmap; + unsigned long dirty_bmap_size; /* Cache of the address space ID */ int as_id; /* Cache of the offset in ram address space */ From patchwork Fri Jan 8 16:50:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dtxXfT+9; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8hQ1KnRz9sW8 for ; Sat, 9 Jan 2021 04:08:54 +1100 (AEDT) Received: from localhost ([::1]:52964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxvFs-0004Dk-1u for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 12:08:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyh-0008Nr-OW for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyf-0005an-E4 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124664; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/XUy2ySdm9sYgEhOIugK6N1I/xZrlp1axcj8OZ5jZyE=; b=dtxXfT+9Ldst+tOoGFpZBX0ICeiiKtP5JUb1mpbM5iQqREAdZU/qxYJkMc39EqViRnlSFo KVdnDISHssMMzflTpb8h4uxdstz83nz7kmdPQj5v/yUfp+zAFMCDVixUmWQHOzpz3Gc3xD YKN/X7SlBPe/iHQMicdfAfwqB3eysy4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-298-Ya2luLLQOS-PvmAvJr-yHw-1; Fri, 08 Jan 2021 11:51:02 -0500 X-MC-Unique: Ya2luLLQOS-PvmAvJr-yHw-1 Received: by mail-qt1-f200.google.com with SMTP id c14so8713997qtn.5 for ; Fri, 08 Jan 2021 08:51:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/XUy2ySdm9sYgEhOIugK6N1I/xZrlp1axcj8OZ5jZyE=; b=WP7hcYap+8zgenszBPi3tGxOEFNuXfTaSjDU3Rv6t/cu59MJgMGRWd3SnIXJTIyq1t ucPWlQyCWryHTqoghY1q4t/4t2D/TfDSwLklAbrDHY6S83l46qbYputqjucOAFhAaHie peC9Qqly/uJgPQqJWcNPGbfQYx+VBSp986ftfUmGJWLAPfl1w7b3NK1YQ7scfArMvhbW 3SRCFo9m5aCDw5WDaH73XjlyuvhnO+VMyOm83g2gtq3tc7ZN8m75iNrMmbBXIpacEzyb QzUSopU9BUFFZd8FZin7/VN8VcNj9M/oYw9LZ/9cWcXG3Si8aKBIsf/BZf2GVVwFpA0A 5EPA== X-Gm-Message-State: AOAM533fbkqxmxYpctpiQB31J8NB0hrIfPkK3QzSCQwqyEHf3F8rHXsc sSxeb4J8iBRmZGTGf123Ct0DbuM92MpFzzCuHQNXPoK6r1HX1Gu0HEszy71Vmakvc3HoH9k7mM0 5GvYV3GhSmeCvhjK4cTbq7dC2/5d49KF+Rchja1Z9fvfmefVV0558nkKdtlD6P54c X-Received: by 2002:ac8:45d7:: with SMTP id e23mr4240992qto.149.1610124661614; Fri, 08 Jan 2021 08:51:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhWJmOwY7nZheMZzM5hSeAPXojPODJ6WC6ibjHRfX6M+x6kH0KjQ/7nHxCCbx5mgx8pRoj1g== X-Received: by 2002:ac8:45d7:: with SMTP id e23mr4240965qto.149.1610124661332; Fri, 08 Jan 2021 08:51:01 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:51:00 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 11/13] KVM: Add dirty-gfn-count property Date: Fri, 8 Jan 2021 11:50:48 -0500 Message-Id: <20210108165050.406906-8-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a parameter for dirty gfn count for dirty rings. If zero, dirty ring is disabled. Otherwise dirty ring will be enabled with the per-vcpu gfn count as specified. If dirty ring cannot be enabled due to unsupported kernel or illegal parameter, it'll fallback to dirty logging. By default, dirty ring is not enabled (dirty-gfn-count default to 0). Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ qemu-options.hx | 12 ++++++++ 2 files changed, 84 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 5339de04cf..77b2c4eb0c 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -130,6 +130,9 @@ struct KVMState KVMMemoryListener *ml; AddressSpace *as; } *as; + bool kvm_dirty_ring_enabled; /* Whether KVM dirty ring is enabled */ + uint64_t kvm_dirty_ring_size; /* Size of the per-vcpu dirty ring */ + uint32_t kvm_dirty_gfn_count; /* Number of dirty GFNs per ring */ }; KVMState *kvm_state; @@ -2137,6 +2140,40 @@ static int kvm_init(MachineState *ms) s->coalesced_pio = s->coalesced_mmio && kvm_check_extension(s, KVM_CAP_COALESCED_PIO); + /* + * Enable KVM dirty ring if supported, otherwise fall back to + * dirty logging mode + */ + if (s->kvm_dirty_gfn_count > 0) { + uint64_t ring_size; + + ring_size = s->kvm_dirty_gfn_count * sizeof(struct kvm_dirty_gfn); + + /* Read the max supported pages */ + ret = kvm_vm_check_extension(s, KVM_CAP_DIRTY_LOG_RING); + if (ret > 0) { + if (ring_size > ret) { + error_report("KVM dirty GFN count %" PRIu32 " too big " + "(maximum is %ld). Please use a smaller value.", + s->kvm_dirty_gfn_count, + ret / sizeof(struct kvm_dirty_gfn)); + ret = -EINVAL; + goto err; + } + + ret = kvm_vm_enable_cap(s, KVM_CAP_DIRTY_LOG_RING, 0, ring_size); + if (ret) { + error_report("Enabling of KVM dirty ring failed: %d. " + "Suggested mininum value is 1024. " + "Please also make sure it's a power of two.", ret); + goto err; + } + + s->kvm_dirty_ring_size = ring_size; + s->kvm_dirty_ring_enabled = true; + } + } + dirty_log_manual_caps = kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | @@ -3191,6 +3228,33 @@ bool kvm_kernel_irqchip_split(void) return kvm_state->kernel_irqchip_split == ON_OFF_AUTO_ON; } +static void kvm_get_dirty_gfn_count(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s = KVM_STATE(obj); + uint32_t value = s->kvm_dirty_gfn_count; + + visit_type_uint32(v, name, &value, errp); +} + +static void kvm_set_dirty_gfn_count(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + KVMState *s = KVM_STATE(obj); + Error *error = NULL; + uint32_t value; + + visit_type_uint32(v, name, &value, &error); + if (error) { + error_propagate(errp, error); + return; + } + + s->kvm_dirty_gfn_count = value; +} + static void kvm_accel_instance_init(Object *obj) { KVMState *s = KVM_STATE(obj); @@ -3198,6 +3262,8 @@ static void kvm_accel_instance_init(Object *obj) s->kvm_shadow_mem = -1; s->kernel_irqchip_allowed = true; s->kernel_irqchip_split = ON_OFF_AUTO_AUTO; + /* KVM dirty ring is by default off */ + s->kvm_dirty_gfn_count = 0; } static void kvm_accel_class_init(ObjectClass *oc, void *data) @@ -3219,6 +3285,12 @@ static void kvm_accel_class_init(ObjectClass *oc, void *data) NULL, NULL); object_class_property_set_description(oc, "kvm-shadow-mem", "KVM shadow MMU size"); + + object_class_property_add(oc, "dirty-gfn-count", "uint32", + kvm_get_dirty_gfn_count, kvm_set_dirty_gfn_count, + NULL, NULL); + object_class_property_set_description(oc, "dirty-gfn-count", + "KVM dirty GFN count (=0 to disable dirty ring)"); } static const TypeInfo kvm_accel_type = { diff --git a/qemu-options.hx b/qemu-options.hx index 459c916d3d..e96e57870c 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -116,6 +116,7 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, " kernel-irqchip=on|off|split controls accelerated irqchip support (default=on)\n" " kvm-shadow-mem=size of KVM shadow MMU in bytes\n" " tb-size=n (TCG translation block cache size)\n" + " dirty-gfn-count=n (KVM dirty ring GFN count, default 0)\n" " thread=single|multi (enable multi-threaded TCG)\n", QEMU_ARCH_ALL) SRST ``-accel name[,prop=value[,...]]`` @@ -150,6 +151,17 @@ SRST where both the back-end and front-ends support it and no incompatible TCG features have been enabled (e.g. icount/replay). + + ``dirty-gfn-count=n`` + When KVM accelerator is used, it controls the per-vcpu KVM dirty ring + size (number of entries one dirty ring contains, per-vcpu). It should + be a value that is power of two, and it should be 1024 or bigger (but + still less than the maximum value that the kernel supports). 4096 + could be a good initial value if you have no idea which is the best. + Set this value to 0 to disable the feature. By default, this feature + is disabled (dirty-gfn-count=0). When enabled, it'll automatically + replace the kvm get dirty log feature. + ERST DEF("smp", HAS_ARG, QEMU_OPTION_smp, From patchwork Fri Jan 8 16:50:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423894 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=arVtS5T1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8l10YBJz9sW8 for ; Sat, 9 Jan 2021 04:11:09 +1100 (AEDT) Received: from localhost ([::1]:59618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxvI3-00075b-2m for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 12:11:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45474) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuyi-0008P4-AJ for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21259) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyf-0005b0-Ne for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cq278E7t9jKibHnaozTkidZOgPVwKtZqvYaNSgg6NcQ=; b=arVtS5T1B3bUMhQSXR8jo/RErP1sO9pX03mCMH/L//nrCPtD4sFJllOOlKturDl8/YBU8h GmxfJCgsObTzJZUPg8AoshEUX2GaM/Y3NksC5uXoIjAW/TQKvTrYWLakK2pHJBPu0mCs4b 89oMZemO1jtVOHkmufge6SBXLolTkcQ= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-544-LIKFhLjxOAeGWw7RICsVKA-1; Fri, 08 Jan 2021 11:51:03 -0500 X-MC-Unique: LIKFhLjxOAeGWw7RICsVKA-1 Received: by mail-qk1-f197.google.com with SMTP id g4so9712623qko.23 for ; Fri, 08 Jan 2021 08:51:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cq278E7t9jKibHnaozTkidZOgPVwKtZqvYaNSgg6NcQ=; b=Z0tEXsDD53AaUEaZAXERmFqFFwKTmP/ke5FzIyMMjvIwodrxZ8SrG3trqJ/vZjvvk4 VA8xvvb2/oVRjAuaQo8QP09XrBVo8Yn/u+VLuijQQVsY9tcEbQGTpRqyF3q/1b5ajWgP lPfR0L3hg0Oz1xw12CJVi9UA2hFsqSoQyHMCpjj5AvNiSsM/88msI9syKdH7av6pwjOs JBtesfdFmQ8dZyUkowU3XcKoYqw3sGo8llin80v/3DNN20HgQnpw5vf8BGlOt7ptwhXI UAG3/3yyKxZpuVUKL+HUFUJbOFOsZSuPThq2BEsJQS2dsC0VWLdVH5udLZZWYhGPJaxA JCXg== X-Gm-Message-State: AOAM533vuop+6dOH2F7VqzMqR5HG996a1eoN/ghFxPtiXCoEpmDFhY0m hn9G768F/QZv2FW+p+I3z1B0Q/e5aF8DHsOAKlivfiT3Sx8C2B6AdPkloZYr4xPeGOz9RcA8bwT Ri2l6QeJFwjN2NTL/EW5V1e0wCwhqnk75C+9Mpc0w5jOskYhOjoHMjAjdd+3VFxZm X-Received: by 2002:a05:620a:1256:: with SMTP id a22mr4730067qkl.484.1610124663075; Fri, 08 Jan 2021 08:51:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7/erfRl033iUfiz0irk/IszQLzDYnvZ0F7SdMuBekKb+Igvjw/IP6WWKjS0KfcXzlqzXUdw== X-Received: by 2002:a05:620a:1256:: with SMTP id a22mr4730041qkl.484.1610124662776; Fri, 08 Jan 2021 08:51:02 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:51:01 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 12/13] KVM: Disable manual dirty log when dirty ring enabled Date: Fri, 8 Jan 2021 11:50:49 -0500 Message-Id: <20210108165050.406906-9-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is for KVM_CLEAR_DIRTY_LOG, which is only useful for KVM_GET_DIRTY_LOG. Skip enabling it for kvm dirty ring. More importantly, KVM_DIRTY_LOG_INITIALLY_SET will not wr-protect all the pages initially, which is against how kvm dirty ring is used - there's no way for kvm dirty ring to re-protect a page before it's notified as being written first with a GFN entry in the ring! So when KVM_DIRTY_LOG_INITIALLY_SET is enabled with dirty ring, we'll see silent data loss after migration. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 77b2c4eb0c..9a9ce0316a 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2174,20 +2174,29 @@ static int kvm_init(MachineState *ms) } } - dirty_log_manual_caps = - kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); - dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | - KVM_DIRTY_LOG_INITIALLY_SET); - s->manual_dirty_log_protect = dirty_log_manual_caps; - if (dirty_log_manual_caps) { - ret = kvm_vm_enable_cap(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2, 0, - dirty_log_manual_caps); - if (ret) { - warn_report("Trying to enable capability %"PRIu64" of " - "KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 but failed. " - "Falling back to the legacy mode. ", - dirty_log_manual_caps); - s->manual_dirty_log_protect = 0; + /* + * KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is not needed when dirty ring is + * enabled. More importantly, KVM_DIRTY_LOG_INITIALLY_SET will assume no + * page is wr-protected initially, which is against how kvm dirty ring is + * usage - kvm dirty ring requires all pages are wr-protected at the very + * beginning. Enabling this feature for dirty ring causes data corruption. + */ + if (!s->kvm_dirty_ring_enabled) { + dirty_log_manual_caps = + kvm_check_extension(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2); + dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | + KVM_DIRTY_LOG_INITIALLY_SET); + s->manual_dirty_log_protect = dirty_log_manual_caps; + if (dirty_log_manual_caps) { + ret = kvm_vm_enable_cap(s, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2, 0, + dirty_log_manual_caps); + if (ret) { + warn_report("Trying to enable capability %"PRIu64" of " + "KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 but failed. " + "Falling back to the legacy mode. ", + dirty_log_manual_caps); + s->manual_dirty_log_protect = 0; + } } } From patchwork Fri Jan 8 16:50:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1423896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OIZYQaKk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DC8nV63b1z9sWl for ; Sat, 9 Jan 2021 04:13:18 +1100 (AEDT) Received: from localhost ([::1]:36384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxvK8-0000qY-QR for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2021 12:13:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxuym-0008Rc-97 for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kxuyi-0005cQ-Ce for qemu-devel@nongnu.org; Fri, 08 Jan 2021 11:51:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610124667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F0wnVJvDnNyiyTa/1KEx6bs59QNS2RNo1RyetJ6ScHw=; b=OIZYQaKkehujgcAHvz3/sg7z6E3UxStGfkHrN2gTci7YHKcaigsONnuLHbhQbQbYbHApd+ 8upgFopccf42zUBt1QolCzeKE1hmIwfdLV1ZnaxrML/LLCkx5Cb9HqgNK5AnO+jSnT/bVL awiytAezQJFBPgC6PAEB2ETnJnG2CJg= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-42-jt8Q4P1adUcF6_PkQiw-1; Fri, 08 Jan 2021 11:51:06 -0500 X-MC-Unique: 42-jt8Q4P1adUcF6_PkQiw-1 Received: by mail-qk1-f199.google.com with SMTP id 189so9745433qko.1 for ; Fri, 08 Jan 2021 08:51:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F0wnVJvDnNyiyTa/1KEx6bs59QNS2RNo1RyetJ6ScHw=; b=C7X070Gdpfg09utguVDeGTUNL8fumtucQQNp/AxiPj7yHVcsFYJVCDAIxR0itVqjQJ twxiTBdBHglKUBkk6wNYB50dRaI/7/hhCoGhGg1Bk/CTKoG4L3wxxeU/UA1rNoPJXFX9 YIPqEnj/Q3l9UyJ73lmiirgv0jnQkwvsVom9GEq6/TItQxxv99E6OuyVLENrJ0EA04io jbZQB5c5zoMhARFBu/o/tTlv7ZCF/kFj6UnI27AuYEadJ4WRxU3hzRzkw7l3v9RT9CUg 7nwILGU+GwhCjteCv7RBLxcddnwk63LNfbzvUhtXTYcvF2FN2cxQGxbz5cS1uIvG5tf+ iSLQ== X-Gm-Message-State: AOAM533EDiODmlSNFSQmnQDGUUtsGJRmgGjKGLdlXUvMaExOswJsMzEw YDWcIYgc+dDOuATvwC8y0gzpakXMe8Ox1bJeFkOAGqa1KNXgiH6wEmAXQtzsiKxHCUPPuoMH6+p Ho8Q8LgObgYGbY0En0twpZOdSVpb4Gbts1CefteaPdM1M80S66bSNrzth7Rv9Pz72 X-Received: by 2002:a05:620a:406:: with SMTP id 6mr4666208qkp.494.1610124665431; Fri, 08 Jan 2021 08:51:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMj0ZAGOj/njKmTL1TvOZXj1cx5diDP0kTV1XCRJD+YdkEpr4jqeCGc6xFMT/y1cM3CcGkuw== X-Received: by 2002:a05:620a:406:: with SMTP id 6mr4666105qkp.494.1610124664033; Fri, 08 Jan 2021 08:51:04 -0800 (PST) Received: from xz-x1.redhat.com ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id n5sm4954064qkh.126.2021.01.08.08.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 08:51:03 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 13/13] KVM: Dirty ring support Date: Fri, 8 Jan 2021 11:50:50 -0500 Message-Id: <20210108165050.406906-10-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210108165050.406906-1-peterx@redhat.com> References: <20210108164601.406146-1-peterx@redhat.com> <20210108165050.406906-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.247, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Hyman , "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" KVM dirty ring is a new interface to pass over dirty bits from kernel to the userspace. Instead of using a bitmap for each memory region, the dirty ring contains an array of dirtied GPAs to fetch (in the form of offset in slots). For each vcpu there will be one dirty ring that binds to it. kvm_dirty_ring_reap() is the major function to collect dirty rings. It can be called either by a standalone reaper thread that runs in the background, collecting dirty pages for the whole VM. It can also be called directly by any thread that has BQL taken. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 331 ++++++++++++++++++++++++++++++++++++++++- accel/kvm/trace-events | 7 + include/hw/core/cpu.h | 8 + 3 files changed, 343 insertions(+), 3 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 9a9ce0316a..691fc6a256 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -15,6 +15,7 @@ #include "qemu/osdep.h" #include +#include #include @@ -78,6 +79,25 @@ struct KVMParkedVcpu { QLIST_ENTRY(KVMParkedVcpu) node; }; +enum KVMDirtyRingReaperState { + KVM_DIRTY_RING_REAPER_NONE = 0, + /* The reaper is sleeping */ + KVM_DIRTY_RING_REAPER_WAIT, + /* The reaper is reaping for dirty pages */ + KVM_DIRTY_RING_REAPER_REAPING, +}; + +/* + * KVM reaper instance, responsible for collecting the KVM dirty bits + * via the dirty ring. + */ +struct KVMDirtyRingReaper { + /* The reaper thread */ + QemuThread reaper_thr; + volatile uint64_t reaper_iteration; /* iteration number of reaper thr */ + volatile enum KVMDirtyRingReaperState reaper_state; /* reap thr state */ +}; + struct KVMState { AccelState parent_obj; @@ -133,6 +153,7 @@ struct KVMState bool kvm_dirty_ring_enabled; /* Whether KVM dirty ring is enabled */ uint64_t kvm_dirty_ring_size; /* Size of the per-vcpu dirty ring */ uint32_t kvm_dirty_gfn_count; /* Number of dirty GFNs per ring */ + struct KVMDirtyRingReaper reaper; }; KVMState *kvm_state; @@ -414,6 +435,13 @@ static int do_kvm_destroy_vcpu(CPUState *cpu) goto err; } + if (cpu->kvm_dirty_gfns) { + ret = munmap(cpu->kvm_dirty_gfns, s->kvm_dirty_ring_size); + if (ret < 0) { + goto err; + } + } + vcpu = g_malloc0(sizeof(*vcpu)); vcpu->vcpu_id = kvm_arch_vcpu_id(cpu); vcpu->kvm_fd = cpu->kvm_fd; @@ -490,6 +518,19 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) (void *)cpu->kvm_run + s->coalesced_mmio * PAGE_SIZE; } + if (s->kvm_dirty_ring_enabled) { + /* Use MAP_SHARED to share pages with the kernel */ + cpu->kvm_dirty_gfns = mmap(NULL, s->kvm_dirty_ring_size, + PROT_READ | PROT_WRITE, MAP_SHARED, + cpu->kvm_fd, + PAGE_SIZE * KVM_DIRTY_LOG_PAGE_OFFSET); + if (cpu->kvm_dirty_gfns == MAP_FAILED) { + ret = -errno; + DPRINTF("mmap'ing vcpu dirty gfns failed: %d\n", ret); + goto err; + } + } + ret = kvm_arch_init_vcpu(cpu); if (ret < 0) { error_setg_errno(errp, -ret, @@ -608,6 +649,11 @@ static void kvm_slot_sync_dirty_pages(KVMSlot *slot) cpu_physical_memory_set_dirty_lebitmap(slot->dirty_bmap, start, pages); } +static void kvm_slot_reset_dirty_pages(KVMSlot *slot) +{ + memset(slot->dirty_bmap, 0, slot->dirty_bmap_size); +} + #define ALIGN(x, y) (((x)+(y)-1) & ~((y)-1)) /* Allocate the dirty bitmap for a slot */ @@ -651,6 +697,170 @@ static void kvm_slot_get_dirty_log(KVMState *s, KVMSlot *slot) } } +/* Should be with all slots_lock held for the address spaces. */ +static void kvm_dirty_ring_mark_page(KVMState *s, uint32_t as_id, + uint32_t slot_id, uint64_t offset) +{ + KVMMemoryListener *kml; + KVMSlot *mem; + + if (as_id >= s->nr_as) { + return; + } + + kml = s->as[as_id].ml; + mem = &kml->slots[slot_id]; + + if (!mem->memory_size || offset >= (mem->memory_size / TARGET_PAGE_SIZE)) { + return; + } + + set_bit(offset, mem->dirty_bmap); +} + +static bool dirty_gfn_is_dirtied(struct kvm_dirty_gfn *gfn) +{ + return gfn->flags == KVM_DIRTY_GFN_F_DIRTY; +} + +static void dirty_gfn_set_collected(struct kvm_dirty_gfn *gfn) +{ + gfn->flags = KVM_DIRTY_GFN_F_RESET; +} + +/* + * Should be with all slots_lock held for the address spaces. It returns the + * dirty page we've collected on this dirty ring. + */ +static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CPUState *cpu) +{ + struct kvm_dirty_gfn *dirty_gfns = cpu->kvm_dirty_gfns, *cur; + uint32_t gfn_count = s->kvm_dirty_gfn_count; + uint32_t count = 0, fetch = cpu->kvm_fetch_index; + + assert(dirty_gfns && gfn_count); + trace_kvm_dirty_ring_reap_vcpu(cpu->cpu_index); + + while (true) { + cur = &dirty_gfns[fetch % gfn_count]; + if (!dirty_gfn_is_dirtied(cur)) { + break; + } + kvm_dirty_ring_mark_page(s, cur->slot >> 16, cur->slot & 0xffff, + cur->offset); + dirty_gfn_set_collected(cur); + trace_kvm_dirty_ring_page(cpu->cpu_index, fetch, cur->offset); + fetch++; + count++; + } + cpu->kvm_fetch_index = fetch; + + return count; +} + +/* Must be with slots_lock held */ +static uint64_t kvm_dirty_ring_reap_locked(KVMState *s) +{ + int ret; + CPUState *cpu; + uint64_t total = 0; + int64_t stamp; + + stamp = get_clock(); + + CPU_FOREACH(cpu) { + total += kvm_dirty_ring_reap_one(s, cpu); + } + + if (total) { + ret = kvm_vm_ioctl(s, KVM_RESET_DIRTY_RINGS); + assert(ret == total); + } + + stamp = get_clock() - stamp; + + if (total) { + trace_kvm_dirty_ring_reap(total, stamp / 1000); + } + + return total; +} + +/* + * Currently for simplicity, we must hold BQL before calling this. We can + * consider to drop the BQL if we're clear with all the race conditions. + */ +static uint64_t kvm_dirty_ring_reap(KVMState *s) +{ + uint64_t total; + + /* + * We need to lock all kvm slots for all address spaces here, + * because: + * + * (1) We need to mark dirty for dirty bitmaps in multiple slots + * and for tons of pages, so it's better to take the lock here + * once rather than once per page. And more importantly, + * + * (2) We must _NOT_ publish dirty bits to the other threads + * (e.g., the migration thread) via the kvm memory slot dirty + * bitmaps before correctly re-protect those dirtied pages. + * Otherwise we can have potential risk of data corruption if + * the page data is read in the other thread before we do + * reset below. + */ + kvm_slots_lock(); + total = kvm_dirty_ring_reap_locked(s); + kvm_slots_unlock(); + + return total; +} + +static void do_kvm_cpu_synchronize_kick(CPUState *cpu, run_on_cpu_data arg) +{ + /* No need to do anything */ +} + +/* + * Kick all vcpus out in a synchronized way. When returned, we + * guarantee that every vcpu has been kicked and at least returned to + * userspace once. + */ +static void kvm_cpu_synchronize_kick_all(void) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + run_on_cpu(cpu, do_kvm_cpu_synchronize_kick, RUN_ON_CPU_NULL); + } +} + +/* + * Flush all the existing dirty pages to the KVM slot buffers. When + * this call returns, we guarantee that all the touched dirty pages + * before calling this function have been put into the per-kvmslot + * dirty bitmap. + * + * This function must be called with BQL held. + */ +static void kvm_dirty_ring_flush(struct KVMDirtyRingReaper *r) +{ + trace_kvm_dirty_ring_flush(0); + /* + * The function needs to be serialized. Since this function + * should always be with BQL held, serialization is guaranteed. + * However, let's be sure of it. + */ + assert(qemu_mutex_iothread_locked()); + /* + * First make sure to flush the hardware buffers by kicking all + * vcpus out in a synchronous way. + */ + kvm_cpu_synchronize_kick_all(); + kvm_dirty_ring_reap(kvm_state); + trace_kvm_dirty_ring_flush(1); +} + /** * kvm_physical_sync_dirty_bitmap - Sync dirty bitmap from kernel space * @@ -1175,7 +1385,24 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, goto out; } if (mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { - kvm_slot_get_dirty_log(kvm_state, mem); + /* + * NOTE: We should be aware of the fact that here we're only + * doing a best effort to sync dirty bits. No matter whether + * we're using dirty log or dirty ring, we ignored two facts: + * + * (1) dirty bits can reside in hardware buffers (PML) + * + * (2) after we collected dirty bits here, pages can be dirtied + * again before we do the final KVM_SET_USER_MEMORY_REGION to + * remove the slot. + * + * Not easy. Let's cross the fingers until it's fixed. + */ + if (kvm_state->kvm_dirty_ring_enabled) { + kvm_dirty_ring_reap_locked(kvm_state); + } else { + kvm_slot_get_dirty_log(kvm_state, mem); + } kvm_slot_sync_dirty_pages(mem); } @@ -1223,6 +1450,51 @@ out: kvm_slots_unlock(); } +static void *kvm_dirty_ring_reaper_thread(void *data) +{ + KVMState *s = data; + struct KVMDirtyRingReaper *r = &s->reaper; + + rcu_register_thread(); + + trace_kvm_dirty_ring_reaper("init"); + + while (true) { + r->reaper_state = KVM_DIRTY_RING_REAPER_WAIT; + trace_kvm_dirty_ring_reaper("wait"); + /* + * TODO: provide a smarter timeout rather than a constant? + */ + sleep(1); + + trace_kvm_dirty_ring_reaper("wakeup"); + r->reaper_state = KVM_DIRTY_RING_REAPER_REAPING; + + qemu_mutex_lock_iothread(); + kvm_dirty_ring_reap(s); + qemu_mutex_unlock_iothread(); + + r->reaper_iteration++; + } + + trace_kvm_dirty_ring_reaper("exit"); + + rcu_unregister_thread(); + + return NULL; +} + +static int kvm_dirty_ring_reaper_init(KVMState *s) +{ + struct KVMDirtyRingReaper *r = &s->reaper; + + qemu_thread_create(&r->reaper_thr, "kvm-reaper", + kvm_dirty_ring_reaper_thread, + s, QEMU_THREAD_JOINABLE); + + return 0; +} + static void kvm_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -1251,6 +1523,36 @@ static void kvm_log_sync(MemoryListener *listener, kvm_slots_unlock(); } +static void kvm_log_sync_global(MemoryListener *l) +{ + KVMMemoryListener *kml = container_of(l, KVMMemoryListener, listener); + KVMState *s = kvm_state; + KVMSlot *mem; + int i; + + /* Flush all kernel dirty addresses into KVMSlot dirty bitmap */ + kvm_dirty_ring_flush(&s->reaper); + + /* + * TODO: make this faster when nr_slots is big while there are + * only a few used slots (small VMs). + */ + kvm_slots_lock(); + for (i = 0; i < s->nr_slots; i++) { + mem = &kml->slots[i]; + if (mem->memory_size && mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { + kvm_slot_sync_dirty_pages(mem); + /* + * This is not needed by KVM_GET_DIRTY_LOG because the + * ioctl will unconditionally overwrite the whole region. + * However kvm dirty ring has no such side effect. + */ + kvm_slot_reset_dirty_pages(mem); + } + } + kvm_slots_unlock(); +} + static void kvm_log_clear(MemoryListener *listener, MemoryRegionSection *section) { @@ -1357,10 +1659,15 @@ void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml, kml->listener.region_del = kvm_region_del; kml->listener.log_start = kvm_log_start; kml->listener.log_stop = kvm_log_stop; - kml->listener.log_sync = kvm_log_sync; - kml->listener.log_clear = kvm_log_clear; kml->listener.priority = 10; + if (s->kvm_dirty_ring_enabled) { + kml->listener.log_sync_global = kvm_log_sync_global; + } else { + kml->listener.log_sync = kvm_log_sync; + kml->listener.log_clear = kvm_log_clear; + } + memory_listener_register(&kml->listener, as); for (i = 0; i < s->nr_as; ++i) { @@ -2297,6 +2604,13 @@ static int kvm_init(MachineState *ms) assert(!ret); } + if (s->kvm_dirty_ring_enabled) { + ret = kvm_dirty_ring_reaper_init(s); + if (ret) { + goto err; + } + } + cpus_register_accel(&kvm_cpus); return 0; @@ -2605,6 +2919,17 @@ int kvm_cpu_exec(CPUState *cpu) case KVM_EXIT_INTERNAL_ERROR: ret = kvm_handle_internal_error(cpu, run); break; + case KVM_EXIT_DIRTY_RING_FULL: + /* + * We shouldn't continue if the dirty ring of this vcpu is + * still full. Got kicked by KVM_RESET_DIRTY_RINGS. + */ + trace_kvm_dirty_ring_full(cpu->cpu_index); + qemu_mutex_lock_iothread(); + kvm_dirty_ring_reap(kvm_state); + qemu_mutex_unlock_iothread(); + ret = 0; + break; case KVM_EXIT_SYSTEM_EVENT: switch (run->system_event.type) { case KVM_SYSTEM_EVENT_SHUTDOWN: diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index e15ae8980d..72a01320a1 100644 --- a/accel/kvm/trace-events +++ b/accel/kvm/trace-events @@ -18,4 +18,11 @@ kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint32_t val, bool assign, uint32_t kvm_set_user_memory(uint32_t slot, uint32_t flags, uint64_t guest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, int ret) "Slot#%d flags=0x%x gpa=0x%"PRIx64 " size=0x%"PRIx64 " ua=0x%"PRIx64 " ret=%d" kvm_clear_dirty_log(uint32_t slot, uint64_t start, uint32_t size) "slot#%"PRId32" start 0x%"PRIx64" size 0x%"PRIx32 kvm_resample_fd_notify(int gsi) "gsi %d" +kvm_dirty_ring_full(int id) "vcpu %d" +kvm_dirty_ring_reap_vcpu(int id) "vcpu %d" +kvm_dirty_ring_page(int vcpu, uint32_t slot, uint64_t offset) "vcpu %d fetch %"PRIu32" offset 0x%"PRIx64 +kvm_dirty_ring_reaper(const char *s) "%s" +kvm_dirty_ring_reap(uint64_t count, int64_t t) "reaped %"PRIu64" pages (took %"PRIi64" us)" +kvm_dirty_ring_reaper_kick(const char *reason) "%s" +kvm_dirty_ring_flush(int finished) "%d" diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 8e7552910d..2ca9e9315e 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -357,6 +357,11 @@ struct qemu_work_item; * @ignore_memory_transaction_failures: Cached copy of the MachineState * flag of the same name: allows the board to suppress calling of the * CPU do_transaction_failed hook function. + * @kvm_dirty_ring_full: + * Whether the kvm dirty ring of this vcpu is soft-full. + * @kvm_dirty_ring_avail: + * Semaphore to be posted when the kvm dirty ring of the vcpu is + * available again. * * State of one CPU core or thread. */ @@ -428,9 +433,12 @@ struct CPUState { */ uintptr_t mem_io_pc; + /* Only used in KVM */ int kvm_fd; struct KVMState *kvm_state; struct kvm_run *kvm_run; + struct kvm_dirty_gfn *kvm_dirty_gfns; + uint32_t kvm_fetch_index; /* Used for events with 'vcpu' and *without* the 'disabled' properties */ DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);