Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1548042rwb; Mon, 7 Nov 2022 03:00:57 -0800 (PST) X-Google-Smtp-Source: AMsMyM4vJCdbQglEFsT1LM0zH5hSd8qWMf2yfGFuqVXL1h749+/UVS6QF0C80kjyYuYxlTHdOMdV X-Received: by 2002:a17:902:d38d:b0:186:9fc5:6c13 with SMTP id e13-20020a170902d38d00b001869fc56c13mr50148679pld.73.1667818857641; Mon, 07 Nov 2022 03:00:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667818857; cv=none; d=google.com; s=arc-20160816; b=HGaNZRpEb30F/0s5q4iaeCSjeYhzUrOXS0LPbKTgaI8y3J33hXHGrf7uGtTBV6BgTs LTeVEQMwyKJEcGrDv6yPu+BzaOXmrEUB9Vn+T/KTTfcSzJXAfPyWU36/NKk8mx+s+NtT gWbvKZH6/0mVyURYxeUasPapioFhE9sxp5fHbbXxZLh7LDHAnRzIvnGvsDQngE4TruHt CCdcM3d8uM+ZQUvWiZ93T6e3H44M9rSvlG26/tiJlp5h+pHrHRco6+6rjk+/JY6E94OE uNv8J0D1Itp6r3CY7GcxULRbGE6kCCHQ/27rlIZmLyCaMaWCzA0iVxaKIYDU4bx/9+B/ V/9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RA5h23L4uCyLHhh8VO30UEa386MUEsaDniZmx0LN9mo=; b=oZrTv/u0QGPLT1eQsllqljEhmn9R+fpt61iHkrXj+4ffYiT4LDMiqdpCXv99hyKzwn Gyk9r3aNw1+MAlTRkjthBD1jc/nt/xqr+D6o16FWVRuIG6SLhXOFo/COylhClNgCuA8k R1ReBAnvo0U8eaB8ngM88EeNZ2f0jP4lbuAnlOKkmLHuhIztiZ3gY9lOIQuJ9w4seNc4 FFPzf3T98I+nhcBz/Ja5Pm6VXnc6D7riGFo3x/vFYfSTlyrc9oJee97NItWBFoRzVNA+ 78uefSAHOumdCd7PzQtoHGK6j70i5dzzF2HcmCdf8gQY4jyQrOaOZiT646d0T77jr08M zhmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NmAsIghB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r8-20020a632048000000b004347b49d045si9540319pgm.631.2022.11.07.03.00.45; Mon, 07 Nov 2022 03:00:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NmAsIghB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231556AbiKGJik (ORCPT + 95 others); Mon, 7 Nov 2022 04:38:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbiKGJih (ORCPT ); Mon, 7 Nov 2022 04:38:37 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A73C10 for ; Mon, 7 Nov 2022 01:37:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667813859; 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=RA5h23L4uCyLHhh8VO30UEa386MUEsaDniZmx0LN9mo=; b=NmAsIghB9OmoFeYrB0WOanNVyeigAaVhFbJm6WG69CN+xKOrBjmqx6x2VYv8af8qxW9AhP /EUr9bmV8g4QDahEInysW2A6/kyBDE1LC/8en3TDLFcx/72GhrYiTdtqyQcJN6ozH4455K JPU28hX5qtRnNMYryAGM9L+FEBPSkCM= Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-372-ogBbAQK4MeuZCHdYF5tFXA-1; Mon, 07 Nov 2022 04:37:37 -0500 X-MC-Unique: ogBbAQK4MeuZCHdYF5tFXA-1 Received: by mail-vk1-f198.google.com with SMTP id u186-20020a1fabc3000000b003b80089c9e6so3153049vke.2 for ; Mon, 07 Nov 2022 01:37:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RA5h23L4uCyLHhh8VO30UEa386MUEsaDniZmx0LN9mo=; b=6UbY6IFR/l39AJg7j8ctRSox7WeOJ9xKmh+agcnA+zuQBJ4VIBXZtZwvlwRCX6uhqe jB7vPGIJeT112/Vnvk/z94L8Wis4tkWqU0aZX5Bm2UBmtgqpweJ+Xa9czBroCLQ28oKz aycRq6L/9oK/gyn0Gmsh0+olOIp6ZyYwan++FuDqo0q4KSVTt6mEtEf9kUs2O1yOWwU0 xlNAo9rkvbGCsDD25a0zCu+c0P8yq52hqxKJdfX+8wOKal2mKzXEY8l6kFtvqmGRAn0l 7QQpo1/B3HujRFYAydexV+ow19gMfzuqTS1R9ZwcNhgWivx/14o6QaYRLlJNxBHQC7OU f1aw== X-Gm-Message-State: ACrzQf1UQ6AaQpwbjR3mNBVHKt9l3VDdrsl/l9TLsZ8jnQ83/YocggKd KPeJj2coM2uW/v+M/o81bLjyzgUcQHIjv8DjMzFcegks40DZeGPBwtMCNoiIuyKc9AiK4VJPSGG YMfWXdUnYn4fMMdZxxd30ZJMJkjKFF9Uz68ODAFzD X-Received: by 2002:a67:c997:0:b0:3aa:1d0c:6bc7 with SMTP id y23-20020a67c997000000b003aa1d0c6bc7mr26593164vsk.16.1667813857378; Mon, 07 Nov 2022 01:37:37 -0800 (PST) X-Received: by 2002:a67:c997:0:b0:3aa:1d0c:6bc7 with SMTP id y23-20020a67c997000000b003aa1d0c6bc7mr26593145vsk.16.1667813857115; Mon, 07 Nov 2022 01:37:37 -0800 (PST) MIME-Version: 1.0 References: <20220915111039.092790446@infradead.org> <20220915111147.890071690@infradead.org> <08bbd7ab-049e-3cc3-f814-636669b856be@citrix.com> In-Reply-To: From: Paolo Bonzini Date: Mon, 7 Nov 2022 10:37:26 +0100 Message-ID: Subject: Re: KVM vs AMD: Re: [PATCH v3 48/59] x86/retbleed: Add SKL return thunk To: Peter Zijlstra Cc: Andrew Cooper , Nathan Chancellor , Thomas Gleixner , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , Linus Torvalds , Tim Chen , Josh Poimboeuf , Pawan Gupta , Johannes Wikner , Alyssa Milburn , Jann Horn , "H.J. Lu" , Joao Moreira , Joseph Nuzman , Steven Rostedt , Juergen Gross , Masami Hiramatsu , Alexei Starovoitov , Daniel Borkmann , K Prateek Nayak , Eric Dumazet , Sean Christopherson , kvm list , Suravee Suthikulpanit Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 Fri, Nov 4, 2022 at 1:45 PM Peter Zijlstra wrote: > > On Thu, Nov 03, 2022 at 10:53:54PM +0000, Andrew Cooper wrote: > > On 21/10/2022 16:21, Nathan Chancellor wrote: > > > On Fri, Oct 21, 2022 at 11:53:09AM +0200, Peter Zijlstra wrote: > > >> On Thu, Oct 20, 2022 at 04:10:28PM -0700, Nathan Chancellor wrote: > > >>> This commit is now in -next as commit 5d8213864ade ("x86/retbleed: Add > > >>> SKL return thunk"). I just bisected an immediate reboot on my AMD test > > >>> system when starting a virtual machine with QEMU + KVM to it (see the > > >>> bisect log below). My Intel test systems do not show this. > > >>> Unfortunately, I do not have much more information, as there are no logs > > >>> in journalctl, which makes sense as the reboot occurs immediately after > > >>> I hit the enter key for the QEMU command. > > >>> > > >>> If there is any further information I can provide or patches I can test > > >>> for further debugging, I am more than happy to do so. > > >> Moo :-( > > >> > > >> you happen to have a .config for me? > > > Sure thing, sorry I did not provide it in the first place! Attached. It > > > has been run through localmodconfig for the particular machine but I > > > assume the core pieces should still be present. > > > > Following up from some debugging on IRC. > > > > The problem is that FILL_RETURN_BUFFER now has a per-cpu variable > > access, and AMD SVM has a fun optimisation where the VMRUN instruction > > doesn't swap, amongst other things, %gs. > > > > per-cpu variables only become safe following > > vmload(__sme_page_pa(sd->save_area)); in svm_vcpu_enter_exit(). > > > > Given that retbleed=force ought to work on non-skylake hardware, the > > appropriate fix is to move the VMLOAD/VMSAVE's down into asm and put > > them adjacent to VMRUN. > > > > This also addresses an undocumented dependency where its only the memory > > clobber in vmload() which stops the compiler moving > > svm_vcpu_enter_exit()'s calculation of sd into an unsafe position. > > So, aside from wasting the entire morning on resuscitating my AMD > Interlagos, I ended up with the below patch which seems to work. > > Not being a virt person, I'm sure I've messed up something, please > advise. Oh, that was fast. I was doing similar stuff to move MSR_IA32_SPEC_CTRL save/restore to assembly, because we're not sure it's safe to do the restore in C code, and there is overlap with this change. I'll get it out today. The main issue in the patch below is that _ASM_ARG4 does not exist on 32-bits, and also _ASM_ARG3 is kinda offlimits because I need it for the aforementioned MSR_IA32_SPEC_CTRL change. Otherwise it's similar to my change. Paolo