Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp9803531rwl; Wed, 11 Jan 2023 10:08:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXvJCMiN7VImGIk2iDkJtHIsK5927d6eIUWKsof+oG82Pv8Ytma2YFRRI0WZw5f2/oIcGY2m X-Received: by 2002:a17:906:e2c5:b0:81d:3231:5920 with SMTP id gr5-20020a170906e2c500b0081d32315920mr59014131ejb.61.1673460535156; Wed, 11 Jan 2023 10:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673460535; cv=none; d=google.com; s=arc-20160816; b=iy5qDEMpEE7lIxtEj8PAkiV0NwFGQwjrWklpPGKEqhO3d+baVcwlSeWMJavORmtEAw 0X05Wfqu/x9YnWpaxusah5Kt3+C1UfiPAsqbV3PS80scR8IvEEd4qxcyVr6KdIVB7LwZ yAD910tCAP7vbbNv4HsOospvWiOjgzgEQ5QCxrzrcYf6ETtIGLgLJN61UA42VQxwLCDV /ZE7igVdj2NM1ul9iBmyQv3RkHhJv7oq65aHoX9AEgqclX1bNcyNanPN7LrC+z/R1Kzs c5WEz3jICyq0eiHIbZl0vmUEatOWpLsF4IqC0mM6qfLvZ8T1oQbBAyDyvz+JgA1NFe6i i6tw== 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; bh=btQ0AMdvOQpF+hu0+WAqnwGM4Ktk9ZWe95MbXLJ3hNk=; b=foy3V/RYqPYyDmnKI/wJp0tyAqe+q01xFPcqa5+0m+y29pHX2oHSbL8gai6GbGeANV UlSPU8Ej1fJGkUmbSkY8umfl33oRr3ek0KShQwDOqfyvUKEnoaGNdDnJsTTnQ8qB81U6 xR8rTo3wyH0Ql7VhxtlyufjGlVRYwzeLJZELlGdHvVapgkqIjX+BjlOMJsuw6DpvmeJe bOQ/bN64FTfjwokYNatXp6CtBase3NarxBtrxxbXhoYmk+rFKMLos13sDnfIst1RXfC5 tAush3tbpY8kvfaCjqWuglMTm9JnIpgMTie3okR24nkWXOR6UJ8+Bq91/eoaQv2Emcv2 tD3w== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds5-20020a170907724500b0084514612c2bsi16857887ejc.610.2023.01.11.10.08.42; Wed, 11 Jan 2023 10:08:55 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233181AbjAKR4Q (ORCPT + 51 others); Wed, 11 Jan 2023 12:56:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232735AbjAKR4P (ORCPT ); Wed, 11 Jan 2023 12:56:15 -0500 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC85913F6D for ; Wed, 11 Jan 2023 09:56:13 -0800 (PST) Received: by mail-ej1-f45.google.com with SMTP id az20so19725444ejc.1 for ; Wed, 11 Jan 2023 09:56:13 -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=btQ0AMdvOQpF+hu0+WAqnwGM4Ktk9ZWe95MbXLJ3hNk=; b=dseTmxcG+k2N+P7eTT5BPkQ6MUOZrDYy7QsLQlEFfFCea8UZfw3qRgjGwt1RHPP1Ny GczgmB1KcIMHlW0gj4flgGOXRAQNitnsRCjbrgqpNqbaj8yep4AjNFZxlY1EX6Nhnz6T +9V8TcdLZl16LqP58aeV2GuS8BEhIMGnJ8hmBn6EERja/yYOS3c41B2wv6w6fE6wuAOK jQAMKHHqtqVAw2LzeTjYp0i9QzXwqCuhAT9oJPIAH9nOl2qsSWeljWk9KPbw/oYVsjl8 cgT9tUQQBoWHjjM4EhpXa0BIDMnd4msDWEjTL3c78psW8OEaS9vW+ivmSFSdOooDdHAJ FaoQ== X-Gm-Message-State: AFqh2kqjF4UQfUXBLHAEEV8H7kdeTapngt3HtPCOwhv7mqFrwpA/0Dwk LIFVK7ccPGBbd+nKTVv0NQ+HOPnfY3K/HxTvmGmc848XIbc= X-Received: by 2002:a17:907:98ee:b0:7c1:5ff0:6cc2 with SMTP id ke14-20020a17090798ee00b007c15ff06cc2mr5350950ejc.246.1673459772403; Wed, 11 Jan 2023 09:56:12 -0800 (PST) MIME-Version: 1.0 References: <20230108030748.158120-1-joanbrugueram@gmail.com> <20230109040531.7888-1-joanbrugueram@gmail.com> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 11 Jan 2023 18:56:01 +0100 Message-ID: Subject: Re: Wake-up from suspend to RAM broken under `retbleed=stuff` To: Peter Zijlstra Cc: Joan Bruguera , linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Andrew Cooper , Juergen Gross , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no 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 Wed, Jan 11, 2023 at 12:20 PM Peter Zijlstra wrote: > > On Mon, Jan 09, 2023 at 04:05:31AM +0000, Joan Bruguera wrote: > > This fixes wakeup for me on both QEMU and real HW > > (just a proof of concept, don't merge) > > > > diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c > > index ffea98f9064b..8704bcc0ce32 100644 > > --- a/arch/x86/kernel/callthunks.c > > +++ b/arch/x86/kernel/callthunks.c > > @@ -7,6 +7,7 @@ > > #include > > #include > > #include > > +#include > > > > #include > > #include > > @@ -150,6 +151,10 @@ static bool skip_addr(void *dest) > > if (dest >= (void *)hypercall_page && > > dest < (void*)hypercall_page + PAGE_SIZE) > > return true; > > +#endif > > +#ifdef CONFIG_PM_SLEEP > > + if (dest == restore_processor_state) > > + return true; > > #endif > > return false; > > } > > diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c > > index 236447ee9beb..e667894936f7 100644 > > --- a/arch/x86/power/cpu.c > > +++ b/arch/x86/power/cpu.c > > @@ -281,6 +281,9 @@ static void notrace __restore_processor_state(struct saved_context *ctxt) > > /* Needed by apm.c */ > > void notrace restore_processor_state(void) > > { > > + /* Restore GS before calling anything to avoid crash on call depth accounting */ > > + native_wrmsrl(MSR_GS_BASE, saved_context.kernelmode_gs_base); > > + > > __restore_processor_state(&saved_context); > > } > > Yeah, I can see why, but I'm not really comfortable with this. TBH, I > don't see how the whole resume code is correct to begin with. At the > very least it needs a heavy dose of noinstr. > > Rafael, what cr3 is active when we call restore_processor_state()? On resume from suspend-to-RAM, the one that was saved by __save_processor_state() AFAICS. On resume from hibernation, it looks like this is the one that was used by the restore kernel. > Specifically, the problem is that I don't feel comfortable doing any > sort of weird code until all the CR and segment registers have been > restored, however, write_cr*() are paravirt functions that result in > CALL, which then gives us a bit of a checken and egg problem. > > I'm also wondering how well retbleed=stuff works on Xen, if at all. If > we can ignore Xen, things are a little earier perhaps.