From nobody Mon May 6 10:07:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605556852; cv=none; d=zohomail.com; s=zohoarc; b=bIAnBH7jqwm3dOBpK3Ge/ZMua5Vf91x+Hg7rsvbD1t2sYbxk58X2vExwibzZj7Dr7gfno57fXCNyGawrSCLHJn4KJA9A9QXV0KOCyvLdKSxlDRAhyd+1jcfxA55Szr4/jM0SIhEwURp4qOgCBTsQr7QMQZ1gcZnmPhFQEy0Q34w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605556852; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QSPnvg9euamjrYg5jqtgzZhjYxiV6NfN68S6J0bI35s=; b=FSyA6ajk6XTl325Ty0llVQwB9NMF0aAEwVY7anUd3Phw8ob2iLzXMuCKJ3AKirsFjGG5IVAVFd0Cwo1rpCvmyyva3f/SkZTXzKEG4LySd9RGTQpNOXJVaFW0CLZCwjAhoZ9fuEUXTITao/bUkBetPhLKgpuXk8WgqFM7F1suut4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605556852529680.8100701487355; Mon, 16 Nov 2020 12:00:52 -0800 (PST) Received: from localhost ([::1]:46260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kekgE-0003Fl-II for importer@patchew.org; Mon, 16 Nov 2020 15:00:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kekdv-0001iK-Ou for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23250) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kekds-00027B-IG for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:27 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-204-j6GX429pP46yJWWk-TW7Ag-1; Mon, 16 Nov 2020 14:58:18 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 440F61007B09; Mon, 16 Nov 2020 19:58:17 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id B70CF19930; Mon, 16 Nov 2020 19:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605556702; 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=QSPnvg9euamjrYg5jqtgzZhjYxiV6NfN68S6J0bI35s=; b=cIYeIRg+pWnGJnZNJXnx/RWTYIAu1nCEXAY3i/IAcW4R4vUdj6Emwn+JbRuO+TJh2gw9jH 9/W4RNt93VuWL0sZLNx4b41H67r/0nBvxW82IHFJeFQczhkJCnZH3w0dFusnGNyQbBWOUm qQGnJfdOL1TWpSbsuNG5x6W0DtREwMs= X-MC-Unique: j6GX429pP46yJWWk-TW7Ag-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 1/5] kvm/i386: Set proper nested state format for SVM Date: Mon, 16 Nov 2020 14:58:11 -0500 Message-Id: <20201116195815.48264-2-pbonzini@redhat.com> In-Reply-To: <20201116195815.48264-1-pbonzini@redhat.com> References: <20201116195815.48264-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/16 04:46:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Tom Lendacky , Marcelo Tosatti , Richard Henderson , Eduardo Habkost , qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky Currently, the nested state format is hardcoded to VMX. This will result in kvm_put_nested_state() returning an error because the KVM SVM support checks for the nested state to be KVM_STATE_NESTED_FORMAT_SVM. As a result, kvm_arch_put_registers() errors out early. Update the setting of the format based on the virtualization feature: VMX - KVM_STATE_NESTED_FORMAT_VMX SVM - KVM_STATE_NESTED_FORMAT_SVM Also, fix the code formatting while at it. Fixes: b16c0e20c7 ("KVM: add support for AMD nested live migration") Cc: Eduardo Habkost Cc: Richard Henderson Cc: Paolo Bonzini Cc: Marcelo Tosatti Signed-off-by: Tom Lendacky Message-Id: Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini --- target/i386/kvm.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index cf46259534..a2934dda02 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1820,12 +1820,14 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 env->nested_state =3D g_malloc0(max_nested_state_len); env->nested_state->size =3D max_nested_state_len; - env->nested_state->format =3D KVM_STATE_NESTED_FORMAT_VMX; =20 if (cpu_has_vmx(env)) { - vmx_hdr =3D &env->nested_state->hdr.vmx; - vmx_hdr->vmxon_pa =3D -1ull; - vmx_hdr->vmcs12_pa =3D -1ull; + env->nested_state->format =3D KVM_STATE_NESTED_FORMAT_VMX; + vmx_hdr =3D &env->nested_state->hdr.vmx; + vmx_hdr->vmxon_pa =3D -1ull; + vmx_hdr->vmcs12_pa =3D -1ull; + } else { + env->nested_state->format =3D KVM_STATE_NESTED_FORMAT_SVM; } } } --=20 2.26.2 From nobody Mon May 6 10:07:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605557132; cv=none; d=zohomail.com; s=zohoarc; b=Ty+Akol00BsrKas9b18isc09ymY1mPrkKlcWNgq/GEWoBBSgmoB+r8/urfNpgyPuh3Drhf7p014FYhqVd7BC7Phu6t+YmkPtGp+XFLUe61DLCX6P8BJXrnngfOX2onrUqOg8viAZedteE6E8W6+goHqhfAFVReujquArj4q2Kl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605557132; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=02qjzftCWqzdeB4G3PIcfBijNIHXHCCvLfAwCNWHEWI=; b=CIFHMfbQ7RmIaOiKtmCOny9mg8ta3zf9R9UppMSs81rjg0GithVxkEr40uTBqgwKOYytq7w2Ttmu0n7FhWgmjqnO49HqzFLtLemPjq31Ko6lrxPuZFoepsEYMxtWeuZ2yBylEGDw7nyxd25PrpZBb1lOyT7JgtCkXWkO7XkGJXM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605557132580386.35721606698496; Mon, 16 Nov 2020 12:05:32 -0800 (PST) Received: from localhost ([::1]:55406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kekkl-00074n-Cf for importer@patchew.org; Mon, 16 Nov 2020 15:05:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1keke6-0001y9-Oq for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1keke3-0002BP-GR for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-Rs-CTJk_NMK-9Lr7GGCP1g-1; Mon, 16 Nov 2020 14:58:32 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6A46D81CBDD; Mon, 16 Nov 2020 19:58:31 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D6A719746; Mon, 16 Nov 2020 19:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605556714; 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=02qjzftCWqzdeB4G3PIcfBijNIHXHCCvLfAwCNWHEWI=; b=K3zhZD+7HkIu5RvbY4+z6WLXPqTwihPjrJHKDMiHVkNT6o7dyccDGV1VFlgYl+JGRwcgH+ pkBAUYiwJ6JcDTRUlUeSvCHlgDrNwWL1w37BCkJoLDgvX2HqQ/TQbAfJs29IVPpM4u+PZ4 8esXK9R5uUWOpGmfY6FeLK4Kn8UXVwA= X-MC-Unique: Rs-CTJk_NMK-9Lr7GGCP1g-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 2/5] util/vfio-helpers.c: Use ram_block_discard_disable() in qemu_vfio_open_pci() Date: Mon, 16 Nov 2020 14:58:12 -0500 Message-Id: <20201116195815.48264-3-pbonzini@redhat.com> In-Reply-To: <20201116195815.48264-1-pbonzini@redhat.com> References: <20201116195815.48264-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/15 22:35:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_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: Pankaj Gupta , "Michael S. Tsirkin" , David Hildenbrand , "Dr . David Alan Gilbert" , Peter Xu , Alex Williamson , Wei Yang , Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Currently, when using "nvme://" for a block device, like -drive file=3Dnvme://0000:01:00.0/1,if=3Dnone,id=3Ddrive0 \ -device virtio-blk,drive=3Ddrive0 \ VFIO may pin all guest memory, and discarding of RAM no longer works as expected. I was able to reproduce this easily with my 01:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM981/PM981/PM983 Similar to common VFIO, we have to disable it, making sure that: a) virtio-balloon won't discard any memory ("silently disabled") b) virtio-mem and nvme:// run mutually exclusive Cc: Paolo Bonzini Cc: "Michael S. Tsirkin" Cc: Alex Williamson Cc: Wei Yang Cc: Dr. David Alan Gilbert Cc: Igor Mammedov Cc: Pankaj Gupta Cc: Peter Xu Signed-off-by: David Hildenbrand Message-Id: <20201116105947.9194-1-david@redhat.com> Signed-off-by: Paolo Bonzini --- stubs/ram-block.c | 6 ++++++ util/vfio-helpers.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/stubs/ram-block.c b/stubs/ram-block.c index 73c0a3ee08..108197683b 100644 --- a/stubs/ram-block.c +++ b/stubs/ram-block.c @@ -1,6 +1,7 @@ #include "qemu/osdep.h" #include "exec/ramlist.h" #include "exec/cpu-common.h" +#include "exec/memory.h" =20 void *qemu_ram_get_host_addr(RAMBlock *rb) { @@ -29,3 +30,8 @@ int qemu_ram_foreach_block(RAMBlockIterFunc func, void *o= paque) { return 0; } + +int ram_block_discard_disable(bool state) +{ + return 0; +} diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index c469beb061..2bec48e163 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -16,6 +16,7 @@ #include "qapi/error.h" #include "exec/ramlist.h" #include "exec/cpu-common.h" +#include "exec/memory.h" #include "trace.h" #include "qemu/error-report.h" #include "standard-headers/linux/pci_regs.h" @@ -494,8 +495,20 @@ QEMUVFIOState *qemu_vfio_open_pci(const char *device, = Error **errp) int r; QEMUVFIOState *s =3D g_new0(QEMUVFIOState, 1); =20 + /* + * VFIO may pin all memory inside mappings, resulting it in pinning + * all memory inside RAM blocks unconditionally. + */ + r =3D ram_block_discard_disable(true); + if (r) { + error_setg_errno(errp, -r, "Cannot set discarding of RAM broken"); + g_free(s); + return NULL; + } + r =3D qemu_vfio_init_pci(s, device, errp); if (r) { + ram_block_discard_disable(false); g_free(s); return NULL; } @@ -837,4 +850,5 @@ void qemu_vfio_close(QEMUVFIOState *s) close(s->device); close(s->group); close(s->container); + ram_block_discard_disable(false); } --=20 2.26.2 From nobody Mon May 6 10:07:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605556872; cv=none; d=zohomail.com; s=zohoarc; b=S0wzqQwKI4wV59cAEw1PNv0ee+fvDCRsETbZzX1umC0H1DGFVdJ/dORl2OzutdR033Wr2Hd10xsn7PRMAPmkrFVHWV3pahYYeLRZn+j4u/b9qK/6CsTq4ncwhVw34zJrk+sJCBM/DWOIaNRkkeT8NleCKiyDn1rmY9ljvfZSeuc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605556872; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BGbIfMBS9cNuyuZ2RI02GE0B9Mc/7KhKZv/nopjOmmA=; b=UIpZrLOjGadDTmopwS3iOhULTGukcYR9kCtE2w+Iy9syNE8qGVC0b1QMgFQEJAz+RJzuGpSwDl8aHstsWnuvSq7QLc2hkrJbV565UoBnrkQAos8BdXik8NaO3plBpmBv6zfEU2UmydpRwF0NK1PL6wq0+X26uLMrkVw6ikwCgnw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605556872752447.3697419202804; Mon, 16 Nov 2020 12:01:12 -0800 (PST) Received: from localhost ([::1]:47264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kekgZ-0003jT-Jk for importer@patchew.org; Mon, 16 Nov 2020 15:01:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1keke5-0001wg-Ob for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59493) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1keke3-0002BQ-ER for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:37 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-532-_cW8W770PZqWV4JXq5n_hw-1; Mon, 16 Nov 2020 14:58:32 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C33A2107466C; Mon, 16 Nov 2020 19:58:31 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8229B19482; Mon, 16 Nov 2020 19:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605556714; 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=BGbIfMBS9cNuyuZ2RI02GE0B9Mc/7KhKZv/nopjOmmA=; b=iHtrSA32lRSXtVpKv8iKH/yy1bSMAU3pUs2IE5l44iuMruAMc4SQFAyOCx2YKSp+aMkplt R/5sFcA3FAQRnhXOc5UHXEqeH2CiT5aq8xPd7VDhVkRIiW6NtXeSrccyd5fCo9Kj6Mt7Cm o6RhtCtRewRCFw3Mnod2QdmoQl8+saU= X-MC-Unique: _cW8W770PZqWV4JXq5n_hw-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 3/5] scsi-disk: convert more errno values back to SCSI statuses Date: Mon, 16 Nov 2020 14:58:13 -0500 Message-Id: <20201116195815.48264-4-pbonzini@redhat.com> In-Reply-To: <20201116195815.48264-1-pbonzini@redhat.com> References: <20201116195815.48264-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/16 04:46:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Hannes Reinecke Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Linux has some OS-specific (and sometimes weird) mappings for various SCSI statuses and sense codes. The most important is probably RESERVATION CONFLICT. Add them so that they can be reported back to the guest kernel. Cc: Hannes Reinecke Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index e859534eaf..90841ad791 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -461,6 +461,25 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int e= rror, bool acct_failed) } error =3D scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.= sense)); break; +#ifdef CONFIG_LINUX + /* These errno mapping are specific to Linux. For more inform= ation: + * - scsi_decide_disposition in drivers/scsi/scsi_error.c + * - scsi_result_to_blk_status in drivers/scsi/scsi_lib.c + * - blk_errors[] in block/blk-core.c + */ + case EBADE: + /* DID_NEXUS_FAILURE -> BLK_STS_NEXUS. */ + scsi_req_complete(&r->req, RESERVATION_CONFLICT); + break; + case ENODATA: + /* DID_MEDIUM_ERROR -> BLK_STS_MEDIUM. */ + scsi_check_condition(r, SENSE_CODE(READ_ERROR)); + break; + case EREMOTEIO: + /* DID_TARGET_FAILURE -> BLK_STS_TARGET. */ + scsi_req_complete(&r->req, HARDWARE_ERROR); + break; +#endif case ENOMEDIUM: scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); break; --=20 2.26.2 From nobody Mon May 6 10:07:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605557234; cv=none; d=zohomail.com; s=zohoarc; b=MS5LpNVNnPHua11u+v4haPHllbFu2VMcEsjpXoUFVwkQktDgxrjDb5e4wB3uKFSCe3hgA6eS5lc6VO81XzTpt6oSECGf4d3dWqtMi4RIPn4qJvxIaCzaF2zLU3vD8W3FdZAgFweqTQqNrvIfwIRafp9AT7fjMN9zdA7NuB/kAd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605557234; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2XVz4iFoJx6xauams/X7I+T8OaFub5vx850hl0DeWt4=; b=brblkegEKFwOzqZVtyVtdL6Ih5/pk5Du4QkCuSeFAUCn9ygBhGGASKc41+l8yY3FM+w0Hvp7SbzSke06q9Tsv9P4C09vEh/rvtKV4DEMpchOcYMB/owUAjX1XdBjT0Kzx6k0KEVlbmgv36GVrKHWDVgyS/gOmeaXVcY3M5SLOic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605557234787144.09715545237816; Mon, 16 Nov 2020 12:07:14 -0800 (PST) Received: from localhost ([::1]:60492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kekmP-0000sV-Ix for importer@patchew.org; Mon, 16 Nov 2020 15:07:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1keke5-0001vp-5j for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54389) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1keke3-0002BS-E9 for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:36 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-Fxvew0ATOIywS6M1Vb5_Tw-1; Mon, 16 Nov 2020 14:58:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C0D95F9DB for ; Mon, 16 Nov 2020 19:58:32 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE19F19D6C for ; Mon, 16 Nov 2020 19:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605556714; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2XVz4iFoJx6xauams/X7I+T8OaFub5vx850hl0DeWt4=; b=UQyCh6by0H84DR+mNwsVbD80J5EZRwY9lkOjx6M4giIH9hO9CxWxUHDguLNkSZfI9hdwTU 53GaYhFQT5hWLfk1dvqwbx4NRQNxMsxS/8SQ4VnzBRKa/cSA+jiz21yYO5ZEULJJQGvWin csdfuRKbl4D0iDe4GM0H/mXhK4GEk5A= X-MC-Unique: Fxvew0ATOIywS6M1Vb5_Tw-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 4/5] target/i386: avoid theoretical leak on MCE injection Date: Mon, 16 Nov 2020 14:58:14 -0500 Message-Id: <20201116195815.48264-5-pbonzini@redhat.com> In-Reply-To: <20201116195815.48264-1-pbonzini@redhat.com> References: <20201116195815.48264-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/15 22:35:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" g_strdup_printf is used twice to write to the same variable, which can theoretically cause a leak. In practice, it is extremely unlikely that a guest is seeing a recursive MCE and has disabled CR4.MCE between the first and the second error, but we can fix it and we can also make a slight improvement on the logic: CR4.MCE=3D0 causes a triple fault even for a non-recursive machine check, so let's place its test first. Signed-off-by: Paolo Bonzini --- target/i386/helper.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/target/i386/helper.c b/target/i386/helper.c index 516ce0cad8..034f46bcc2 100644 --- a/target/i386/helper.c +++ b/target/i386/helper.c @@ -908,16 +908,14 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cp= u_data data) return; } =20 - if (recursive) { - need_reset =3D true; - msg =3D g_strdup_printf("CPU %d: Previous MCE still in progres= s, " - "raising triple fault", cs->cpu_index); - } - if (!(cenv->cr[4] & CR4_MCE_MASK)) { need_reset =3D true; msg =3D g_strdup_printf("CPU %d: MCE capability is not enabled= , " "raising triple fault", cs->cpu_index); + } else if (recursive) { + need_reset =3D true; + msg =3D g_strdup_printf("CPU %d: Previous MCE still in progres= s, " + "raising triple fault", cs->cpu_index); } =20 if (need_reset) { --=20 2.26.2 From nobody Mon May 6 10:07:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1605556880; cv=none; d=zohomail.com; s=zohoarc; b=BC/JzvmgPgR3mn3KvSQuxkfvnW1x+razqdpuHYNQUSQDw+vPzbqHMcPBpuxYice0DE95Of2uQkUoUp64bjo6w/RrYlPrOTUBwX94N19PfpVuygUOUOBj02fAvGtzzp7rrsBZB5PAfnFJpIZSq0RKhF4GF8SEm38kd6qszjnDxyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605556880; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=V0786/vOvgHEBpgfXjgeCuSnzS82fexkT8gf6hqUsYM=; b=C8YO6jPFQQQM97wXjaE7UKVb5V6df2cjM5DUxWIrvnrvkV9+31l48gcXYIlm7twzT82js9RV01fF4WM3SsXpjMMF8XaiJnHegU8/CxJtm+h/L9FnINSxifMU++lrUBed2JK8xG+Xu+purBolrN/ZPAhsqbmbouAIZhmp1+JE9tU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1605556880285219.0184314895664; Mon, 16 Nov 2020 12:01:20 -0800 (PST) Received: from localhost ([::1]:47510 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kekgh-0003pU-69 for importer@patchew.org; Mon, 16 Nov 2020 15:01:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1keke9-000216-1p for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47461) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1keke5-0002CU-Qe for qemu-devel@nongnu.org; Mon, 16 Nov 2020 14:58:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-384-5AcyXsCIOgKZI7S3YS3tkA-1; Mon, 16 Nov 2020 14:58:33 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B32A41074653; Mon, 16 Nov 2020 19:58:32 +0000 (UTC) Received: from virtlab511.virt.lab.eng.bos.redhat.com (virtlab511.virt.lab.eng.bos.redhat.com [10.19.152.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35F8F19D6C; Mon, 16 Nov 2020 19:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605556717; 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=V0786/vOvgHEBpgfXjgeCuSnzS82fexkT8gf6hqUsYM=; b=D8h76p9+WiajcjU4wJiQUidb58+kXGgNGRHCmmNGI9VNyz6Y3maMuAeQvkA7Ko2y5BZPjQ pZKa8gUT4398NPXxfgO9d2u8GFCuQOH29fpUTMYl73DJNvn0lOy0VKI8tZYW14oV0zL5dW fRNH4UqOSYt/JQtvO7D5ZirFbLUuh18= X-MC-Unique: 5AcyXsCIOgKZI7S3YS3tkA-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 5/5] memory: Skip dirty tracking for un-migratable memory regions Date: Mon, 16 Nov 2020 14:58:15 -0500 Message-Id: <20201116195815.48264-6-pbonzini@redhat.com> In-Reply-To: <20201116195815.48264-1-pbonzini@redhat.com> References: <20201116195815.48264-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/16 04:46:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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: Zenghui Yu , Cornelia Huck Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Zenghui Yu It makes no sense to track dirty pages for those un-migratable memory regions (e.g., Memory BAR region of the VFIO PCI device) and doing so will potentially lead to some unpleasant issues during migration [1]. Skip dirty tracking for those regions by evaluating if the region is migratable before setting dirty_log_mask (DIRTY_MEMORY_MIGRATION). [1] https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg03757.html Signed-off-by: Zenghui Yu Message-Id: <20201116132210.1730-1-yuzenghui@huawei.com> Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini --- softmmu/memory.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 71951fe4dc..aa393f1bb0 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1806,7 +1806,10 @@ bool memory_region_is_ram_device(MemoryRegion *mr) uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) { uint8_t mask =3D mr->dirty_log_mask; - if (global_dirty_log && (mr->ram_block || memory_region_is_iommu(mr)))= { + RAMBlock *rb =3D mr->ram_block; + + if (global_dirty_log && ((rb && qemu_ram_is_migratable(rb)) || + memory_region_is_iommu(mr))) { mask |=3D (1 << DIRTY_MEMORY_MIGRATION); } return mask; --=20 2.26.2