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,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 844B6C433DF for ; Thu, 15 Oct 2020 15:16:29 +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 0EF3D2222B for ; Thu, 15 Oct 2020 15:16:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="nEaako62" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EF3D2222B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.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.7486.19573 (Exim 4.92) (envelope-from ) id 1kT4zI-0002NP-6B; Thu, 15 Oct 2020 15:16:16 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 7486.19573; Thu, 15 Oct 2020 15:16:16 +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 1kT4zI-0002NI-36; Thu, 15 Oct 2020 15:16:16 +0000 Received: by outflank-mailman (input) for mailman id 7486; Thu, 15 Oct 2020 15:16:14 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kT4zG-0002ND-Sr for xen-devel@lists.xenproject.org; Thu, 15 Oct 2020 15:16:14 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f7453203-569d-4d1a-8c1d-b9f8215774a5; Thu, 15 Oct 2020 15:16:05 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AB6FFAB0E; Thu, 15 Oct 2020 15:16:04 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kT4zG-0002ND-Sr for xen-devel@lists.xenproject.org; Thu, 15 Oct 2020 15:16:14 +0000 X-Inumbo-ID: f7453203-569d-4d1a-8c1d-b9f8215774a5 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id f7453203-569d-4d1a-8c1d-b9f8215774a5; Thu, 15 Oct 2020 15:16:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602774964; 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=KI5wVx4FRmhvGSkYP6r+ArTuozQ8lzQpP3Xv0BQ96Kc=; b=nEaako62Sup5pZxVlPOqzQ3Lntw9r2NNlM8EpvinE6mMROTPDm97eZ1nZvadqcSSRGm1Dl btEF2RHfei1ToFu0mLacIbYjt19igqNAVUeVLleHW2HRKKEB6G9VO2SwFSuD+zvhmSSPyi 4u4nQMPQXXk8MBI4p1fsVpffB61sWZI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id AB6FFAB0E; Thu, 15 Oct 2020 15:16:04 +0000 (UTC) Subject: Re: [PATCH v2] x86/smpboot: Don't unconditionally call memguard_guard_stack() in cpu_smpboot_alloc() To: Andrew Cooper 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> <0a294279-5de5-3b54-b1f9-847de1159447@citrix.com> From: Jan Beulich Message-ID: <578a0afd-693a-c704-317e-477e5e27d497@suse.com> Date: Thu, 15 Oct 2020 17:16:05 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <0a294279-5de5-3b54-b1f9-847de1159447@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 15.10.2020 16:02, Andrew Cooper wrote: > 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 didn't think it was the BSP's stack that got written to, but the first AP's before letting it run. Jan