Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2828206ybv; Sat, 15 Feb 2020 04:33:17 -0800 (PST) X-Google-Smtp-Source: APXvYqzkxQqnY+WDY6rOlwbqCwbcSf2YqdDm2+AB4BlpqEkPCpmRZox4Nzm0GaszdbVZdBkx7GiL X-Received: by 2002:a05:6830:11c8:: with SMTP id v8mr5403981otq.330.1581769997483; Sat, 15 Feb 2020 04:33:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581769997; cv=none; d=google.com; s=arc-20160816; b=u2MkoAKwgNTqwjww5Fx68+ujmfhAIE9CgO/RkcAz2SaFnuYSJA1dY59mwPBb5ynRD2 WQSQ5BNcTTxjJr4VFD+2pstIFbvy0MGLl1ucCrWkBfUnXI1mznKVIltuXv9ziIyeUCyN wjyUYVpYV7GeHg1+iVX7R0CF5yp1y3SjcPhgqS/DiJBTmlkXAg6616lJtlmUSDryAAnq +tYHKYGFSfNkUHcRuGe2HQbcQMW/pV4cb28QFk2qONiAIQoDwRp+m+sk7EKW/KKW7frs vGGPRVSnyieHNcYkhoLcIA1oDExai+aNWyOzJJPFJ2sYomSaAYKgmz7MfmmcAW7oaakA uNcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=XhkdvHXUYSNdBQ6tzgOLvfDXAg3HkzuOmNvmk6HkM1w=; b=RltT2A4at1rOALRtagisFJoL9sBwo4l89im+UQHxKpbgQOBj2ox229mBOw6Vd9LuvR XBX2oNmULo3gRWJWOnoK0zi6tjQSj+PLjZVQVy9Et3KeNZEOwgFQ2NoSZWyaIhRKDsF2 CJvpAeH9EVPwanDXhOiGXa2R8noHZhnJz47bfrZv7a45fvd8Mi+ebVXZctQDFnPu3EKQ UXiDfh4lMsKuMMCsfx04VAofvHYwF5euhIiY90UI/j5s1aD9S8EQ20fDwJEpvzlebTjQ Vd7gHLmqo249QyoDklOH9Kg8lswufmU9XH57UuGkXu0nVFCqmoWVbXKD/lW29yS73rec fuFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r21si4239542ota.204.2020.02.15.04.33.05; Sat, 15 Feb 2020 04:33:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbgBOMcw (ORCPT + 99 others); Sat, 15 Feb 2020 07:32:52 -0500 Received: from 8bytes.org ([81.169.241.247]:54312 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725937AbgBOMcw (ORCPT ); Sat, 15 Feb 2020 07:32:52 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 7A23E2C2; Sat, 15 Feb 2020 13:32:50 +0100 (CET) Date: Sat, 15 Feb 2020 13:32:48 +0100 From: Joerg Roedel To: Andi Kleen Cc: x86@kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, Joerg Roedel Subject: Re: [PATCH 08/62] x86/boot/compressed/64: Add IDT Infrastructure Message-ID: <20200215123248.GF22063@8bytes.org> References: <20200211135256.24617-1-joro@8bytes.org> <20200211135256.24617-9-joro@8bytes.org> <87k14p5557.fsf@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k14p5557.fsf@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 14, 2020 at 11:40:36AM -0800, Andi Kleen wrote: > Joerg Roedel writes: > > + addq $8, %rsp > > + > > + /* > > + * Make sure we return to __KERNEL_CS - the CS selector on > > + * the IRET frame might still be from an old BIOS GDT > > + */ > > + movq $__KERNEL_CS, 8(%rsp) > > This doesn't make sense. Either it's running on the correct CS > before the exception or not. Likely there's some other problem > here that you patched over with this hack. It is actually a well-known situation and not some other problem. The boot-code loaded a new GDT and IDT, but did not reload CS with a far jump/ret/call. The CS value loaded is undefined and comes from the UEFI BIOS. When an exception is raised, this old CS value is stored in the IRET frame, and when IRET is executed the processor loads an undefined CS value, which causes a triple fault with the current IDT setup. The hack in this patch just fixes the IRET frame up so that it will return to the correct CS. The reason for this hack was actually to safe some instructions in the boot-path, because the space is limited there between the defined offsets of the various entry points. I removed this hack meanwhile and added a separate function which reloads CS, DS, SS and ES and which is called from the boot-path, so that there is no problem with the offsets. Regards, Joerg