From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAE75C433E7 for ; Thu, 15 Oct 2020 14:03:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4419720663 for ; Thu, 15 Oct 2020 14:03:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="GKJUmsCy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4419720663 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.7403.19322 (Exim 4.92) (envelope-from ) id 1kT3qG-0002UQ-Vc; Thu, 15 Oct 2020 14:02:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 7403.19322; Thu, 15 Oct 2020 14:02:52 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kT3qG-0002UJ-S9; Thu, 15 Oct 2020 14:02:52 +0000 Received: by outflank-mailman (input) for mailman id 7403; Thu, 15 Oct 2020 14:02:50 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kT3qE-0002U3-OT for xen-devel@lists.xenproject.org; Thu, 15 Oct 2020 14:02:50 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f95744fe-b802-4a0a-8d5d-e93722dcb3ee; Thu, 15 Oct 2020 14:02:49 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kT3qE-0002U3-OT for xen-devel@lists.xenproject.org; Thu, 15 Oct 2020 14:02:50 +0000 X-Inumbo-ID: f95744fe-b802-4a0a-8d5d-e93722dcb3ee Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f95744fe-b802-4a0a-8d5d-e93722dcb3ee; Thu, 15 Oct 2020 14:02:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1602770570; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=vJmFyAUEzqg6ecFBFpUq4RyHD+WUMAaJ+2eNPktHAdo=; b=GKJUmsCyZTYXcaefd7ScZW1oB7oJE818VFSmeYN9fLbhoRCxZDr3p9js ZfGU9AAN9NAYqij79+xit7Chfj5jQjYe+Hbg3SUBF4QecnQxQ1dipZFoJ EwOEPuMLVDBPCZovOJLO1/Ip4ge0VKi6x19fQEQeGwiXEaLvFk53G1kxY A=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: kmYhWeC8acTVT2lKvp+ywlNO8ZYGSPIKuI/DKZo4eiAkK1F7pCmiWhvLJx9qELnrEVdFxBngDr G5o4oIBM0ghyQjJJh1GYPiMG04gN73CVzZsxTBoYdNQEXepgZuFwqf22b5Ho/nVG5fnmyhjQc9 op+OCY8PzgsvZ31UVFzq+17yRc/Dxhjco9Drh/yDAMUk/S/0Nwkjt9EMoLVcVfDL5riA2D786/ 6kgGtCRm8XeiWQiLwClixvbrmvXUK9f6dAxCf1tIwnpO8zWLm0lqfeKxEz/IIs6k2P6NH7Ao+J 7Ww= X-SBRS: 2.5 X-MesageID: 29410899 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.77,379,1596513600"; d="scan'208";a="29410899" Subject: Re: [PATCH v2] x86/smpboot: Don't unconditionally call memguard_guard_stack() in cpu_smpboot_alloc() To: Jan Beulich CC: Xen-devel , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , Wei Liu References: <20201014184708.17758-1-andrew.cooper3@citrix.com> <0ed412d9-c9a2-194b-c953-c74ee102664f@suse.com> From: Andrew Cooper Message-ID: <0a294279-5de5-3b54-b1f9-847de1159447@citrix.com> Date: Thu, 15 Oct 2020 15:02:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <0ed412d9-c9a2-194b-c953-c74ee102664f@suse.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Content-Language: en-GB X-ClientProxiedBy: AMSPEX02CAS02.citrite.net (10.69.22.113) To FTLPEX02CL05.citrite.net (10.13.108.178) On 15/10/2020 09:50, Jan Beulich wrote: > On 14.10.2020 20:47, Andrew Cooper wrote: >> cpu_smpboot_alloc() is designed to be idempotent with respect to partially >> initialised state. This occurs for S3 and CPU parking, where enough state to >> handle NMIs/#MCs needs to remain valid for the entire lifetime of Xen, even >> when we otherwise want to offline the CPU. >> >> For simplicity between various configuration, Xen always uses shadow stack >> mappings (Read-only + Dirty) for the guard page, irrespective of whether >> CET-SS is enabled. >> >> Unfortunately, the CET-SS changes in memguard_guard_stack() broke idempotency >> by first writing out the supervisor shadow stack tokens with plain writes, >> then changing the mapping to being read-only. >> >> This ordering is strictly necessary to configure the BSP, which cannot have >> the supervisor tokens be written with WRSS. >> >> Instead of calling memguard_guard_stack() unconditionally, call it only when >> actually allocating a new stack. Xenheap allocates are guaranteed to be >> writeable, and the net result is idempotency WRT configuring stack_base[]. >> >> Fixes: 91d26ed304f ("x86/shstk: Create shadow stacks") >> Reported-by: Marek Marczykowski-Górecki >> Signed-off-by: Andrew Cooper >> --- >> CC: Jan Beulich >> CC: Roger Pau Monné >> CC: Wei Liu >> >> This can more easily be demonstrated with CPU hotplug than S3, and the absence >> of bug reports goes to show how rarely hotplug is used. >> >> v2: >> * Don't break S3/CPU parking in combination with CET-SS. v1 would, for S3, >> turn the BSP shadow stack into regular mappings, and #DF as soon as the TLB >> shootdown completes. > The code change looks correct to me, but since I don't understand > this part I'm afraid I may be overlooking something. I understand > the "turn the BSP shadow stack into regular mappings" relates to > cpu_smpboot_free()'s call to memguard_unguard_stack(), but I > didn't think we come through cpu_smpboot_free() for the BSP upon > entering or leaving S3. The v1 really did fix Marek's repro of the problem. The only possible way this can occur is if, somewhere, there is a call to cpu_smpboot_free() for CPU0 with remove=0 on the S3 path I have to admit that I can't actually spot where it is. Either way - it doesn't impact the fix, which attempts to make "the stack" into a single object.  I experimented with introducing smpboot_{alloc,free}_stack(), but the result wasn't clean and I abandoned that approach. ~Andrew