Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2105943iof; Tue, 7 Jun 2022 19:57:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfqA+aS/MowUTrB70H7jXOg6RowrMLb5EIayA9Ct6DQYQUkCRM1lDuz/lfIzxakhaUhJTB X-Received: by 2002:a17:902:7b8e:b0:167:726e:f66a with SMTP id w14-20020a1709027b8e00b00167726ef66amr16106530pll.144.1654657026054; Tue, 07 Jun 2022 19:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654657026; cv=none; d=google.com; s=arc-20160816; b=bliD770znhIz1XecfG6ocoJqGhgX5xm/0WXgU33CT3ToxCqBJUMUA1U8E0b4ACip0f RJSga2UuipmL9citA0FCvkNTHPNkF6iD8HVVaA/nrXM8OZ6yyaR/SuHtBDKS0A+fTYUE YMe+GAVFz2O1hm0+BsKYIs2PDn1r+6jUe34X6PJi9WNv1lJYVdGpvL37MZZuSJRNc8X5 i+NyjxTseDrHSKR742wibIG4X7Mmv5NC19byjAbe+VclkqyuKQ/Ks6HzMQd+D7JGddEP pwHFT0WinZ9a+Il8oRuWAd28P6Q9OIIcIJ3nfxcdnwPZIQNzMIP7/wqfQlw9oU7vrOvq lMQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=j3lpgWA7svbHLWKqRID/rVg39qDI+lSSGg7Fd1qcSWA=; b=IGhYij9lPcbjIE/0jwXlexayvu1101FiXJK0wEo8HeoflHE7QA4tP6XfiAJRReiIQ4 SCSBqvXkysKrgp8ff3di+b5ACHaPDn15zCe50oWAAd9uQwM0N5fqZ2wYdO/78eqQWLP1 fG3Rk5Dx9T4mLvHNPm3faCIvTioP6MHj9ByXP5Mj9MUWt6R4/yqRMjImlj6JIjftHKrK zgxwNTIwljX6VZiWP6IUrQiyksRDrGiODuHnc6+nw7PFssC2KWutmkNS5+tAMcRK4BVS QIpQSt7LSuW/TIZETmgWiweKUog6LTQ39gtU0Kb/w4rA2fwhfuEuOM4vBX7TXWVgADXZ qvhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HX337raf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v19-20020a170902d09300b00163e051ed3bsi21837715plv.338.2022.06.07.19.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 19:57:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HX337raf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7D8582C2781; Tue, 7 Jun 2022 18:47:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376281AbiFGUqP (ORCPT + 99 others); Tue, 7 Jun 2022 16:46:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354478AbiFGTmy (ORCPT ); Tue, 7 Jun 2022 15:42:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 40E7335852 for ; Tue, 7 Jun 2022 11:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654625879; 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: in-reply-to:in-reply-to:references:references; bh=j3lpgWA7svbHLWKqRID/rVg39qDI+lSSGg7Fd1qcSWA=; b=HX337rafDRTQ40tPfGzLBm+OFRzCstT5rSuQRIdkfDNaZtP5lq48MgdiyXEEXj+sKQJ3ER TLhMf6ZecaY0XkG1CC9sqRBNrA0AbYusyWsDaP3bBsUqT4nB/ZHB/Ip+NtX5bNqfUQjx4Z sMLb2wBS1OdaJpHemI3cK0TyVWxyQDg= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-154-8pl5M3nMPpeLW4PtvwLURw-1; Tue, 07 Jun 2022 14:17:58 -0400 X-MC-Unique: 8pl5M3nMPpeLW4PtvwLURw-1 Received: by mail-io1-f71.google.com with SMTP id w16-20020a5d8450000000b00669877b9ce2so709632ior.20 for ; Tue, 07 Jun 2022 11:17:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=j3lpgWA7svbHLWKqRID/rVg39qDI+lSSGg7Fd1qcSWA=; b=cYkxqBDOTcc0ISgsH6U/X6ULcLIVbmWGM21jPbHpAhr3HHi+GWvSMF9SM15gfM4byM snCga2HUoy8KzMhtR1A/7N5qLkhqMuLSBvHFt1lvxdbwpqpBeUVMzP0qxSC3kOD+Y+nF Iaea6JlhWbGxMC2L0cpZ+RlhDxlkOFx8lA1043SdjHbrpP7ECksVnzy/LLau1WwfBr3Y Sak95Mc4/v95KVstM+n/ge8pFatxHjfaAyYpzev1woYaP+mPykzrQ3eGeLNiLq/CuyM6 5kgfvlQ9Y7OWnDFMUv0PMZ/lddBZ6wJlZHNy9SG27XY2NZHDbticZx5e5TmGKK7AuGr6 r1og== X-Gm-Message-State: AOAM531gPnJ4DLSnGZjHSGtjlK/n/FqSfXWRp1C72RJ+pPNVfJf2fvS+ h6gBJm1HVXpl1CG1GpBjiWLgLetvwft1P0ZLlPtP2DOv/3ZAS/y9Kx8qRY2RwoYOJqBHazSD7fR HST/xj/iYsevtRMvdyOi7YHXK X-Received: by 2002:a05:6602:2e8d:b0:64f:b683:c70d with SMTP id m13-20020a0566022e8d00b0064fb683c70dmr14718160iow.62.1654625877416; Tue, 07 Jun 2022 11:17:57 -0700 (PDT) X-Received: by 2002:a05:6602:2e8d:b0:64f:b683:c70d with SMTP id m13-20020a0566022e8d00b0064fb683c70dmr14718146iow.62.1654625877100; Tue, 07 Jun 2022 11:17:57 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id x8-20020a92d648000000b002d517c65c51sm4060827ilp.88.2022.06.07.11.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 11:17:56 -0700 (PDT) Date: Tue, 7 Jun 2022 14:17:54 -0400 From: Peter Xu To: Sean Christopherson Cc: Paolo Bonzini , Sasha Levin , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Leonardo Bras , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, chang.seok.bae@intel.com, luto@kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH AUTOSEL 5.16 07/28] x86/kvm/fpu: Limit guest user_xfeatures to supported bits of XCR0 Message-ID: References: <20220301201344.18191-1-sashal@kernel.org> <20220301201344.18191-7-sashal@kernel.org> <5f2b7b93-d4c9-1d59-14df-6e8b2366ca8a@redhat.com> <2d9ba70b-ac18-a461-7a57-22df2c0165c6@redhat.com> <9d336622-6964-454a-605f-1ca90b902836@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 07, 2022 at 03:04:27PM +0000, Sean Christopherson wrote: > On Tue, Jun 07, 2022, Paolo Bonzini wrote: > > On 6/6/22 23:27, Peter Xu wrote: > > > On Mon, Jun 06, 2022 at 06:18:12PM +0200, Paolo Bonzini wrote: > > > > > However there seems to be something missing at least to me, on why it'll > > > > > fail a migration from 5.15 (without this patch) to 5.18 (with this patch). > > > > > In my test case, user_xfeatures will be 0x7 (FP|SSE|YMM) if without this > > > > > patch, but 0x0 if with it. > > > > > > > > What CPU model are you using for the VM? > > > > > > I didn't specify it, assuming it's qemu64 with no extra parameters. > > > > Ok, so indeed it lacks AVX and this patch can have an effect. > > > > > > For example, if the source lacks this patch but the destination has it, > > > > the source will transmit YMM registers, but the destination will fail to > > > > set them if they are not available for the selected CPU model. > > > > > > > > See the commit message: "As a bonus, it will also fail if userspace tries to > > > > set fpu features (with the KVM_SET_XSAVE ioctl) that are not compatible to > > > > the guest configuration. Such features will never be returned by > > > > KVM_GET_XSAVE or KVM_GET_XSAVE2." > > > > > > IIUC you meant we should have failed KVM_SET_XSAVE when they're not aligned > > > (probably by failing validate_user_xstate_header when checking against the > > > user_xfeatures on dest host). But that's probably not my case, because here > > > KVM_SET_XSAVE succeeded, it's just that the guest gets a double fault after > > > the precopy migration completes (or for postcopy when the switchover is > > > done). > > > > Difficult to say what's happening without seeing at least the guest code > > around the double fault (above you said "fail a migration" and I thought > > that was a different scenario than the double fault), and possibly which was > > the first exception that contributed to the double fault. > > Regardless of why the guest explodes in the way it does, is someone planning on > bisecting this (if necessary?) and sending a backport to v5.15? There's another > bug report that is more than likely hitting the same bug. What's the bisection you mentioned? I actually did a bisection and I also checked reverting Leo's change can also fix this issue. Or do you mean something else? > > https://lore.kernel.org/all/48353e0d-e771-8a97-21d4-c65ff3bc4192@sentex.net That is kvm64, and I agree it could be the same problem since both qemu64 and kvm64 models do not have any xsave feature bit declared in cpuid 0xd, so potentially we could be migrating some fpu states to it even with user_xfeatures==0 on dest host. So today I continued the investigation, and I think what's really missing is qemu seems to be ignoring the user_xfeatures check for KVM_SET_XSAVE and continues even if it returns -EINVAL. IOW, I'm wondering whether we should fail properly and start to check kvm_arch_put_registers() retcode. But that'll be a QEMU fix, and it'll at least not causing random faults (e.g. double faults) in guest but we should fail the migration gracefully. Sean: a side note is that I can also easily trigger one WARN_ON_ONCE() in your commit 98c25ead5eda5 in kvm_arch_vcpu_ioctl_run(): WARN_ON_ONCE(kvm_lapic_hv_timer_in_use(vcpu)); It'll be great if you'd like to check that up. Thanks, -- Peter Xu