Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5951739ybv; Wed, 12 Feb 2020 03:21:30 -0800 (PST) X-Google-Smtp-Source: APXvYqw0XfKU8PKfN+LSTUFiFHGua51oCvaaASlBiSRRy05IqoRyhid97wwdz7Jq8pKL3YDIU/zL X-Received: by 2002:a9d:6b03:: with SMTP id g3mr8861945otp.200.1581506490794; Wed, 12 Feb 2020 03:21:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581506490; cv=none; d=google.com; s=arc-20160816; b=jOoZwG47ZBXH8kkHh+82yLgzdneyvm7aAj+1/5vx9DPvfvknjos3A4qwgzwJGg8fd8 pOgQX/ZseLA5Da9Zji6qiuVvXJqLRAlPokS2pzxwc3YRQX+85cas0UvoySpu/8DrCdDr yz+wvYK0Y9RJFy9zhSJswxUuEevU/DIgsoPIEMFptQimzCgq7ZtXzLPuW1W5NSn8fkYK YdC4vL1xIh4JBxqNi3dYbjZqaVVjhdVH+M5wLFOsNq2dh4UqcgigO/+PHJLfxEUc8eAU 4bhlUcCgw4RgVW5Eq8shNwF4AggF+bivEmrD9L4Q/I+3F541Un4nlc5+lpXrBTwCVhqf BFNQ== 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=2+l3IFgXqfY2NxHkzlhdTlw2Rp6BaW95Dy9iSLDVM24=; b=tsTTb+3No7rVf7m6Bi7IHQU2j5mowZoWuyWgY8V+t+O62uEPbcXMgLYm3y65B8BSuD D80/gb1vO6olEk1yYDQcqUpnlG0ccsUnDT5AJWck9JTYe/rraB2bmC8zNiqlc5e7DGPF 4QBolT3tatQSCa5BVA9LJ7Bj8+8tMQNP1g8BuTyp70Uw+5YhwPfkHxSDYpdFZb8SSXMY 9LVuHJTeG8NwbfZtBsiVsO8XobA9OnKsR0Lnd2Y6kr+TrjojYYX9TYIcKWo7t7mwrgOh 8Ndgt4e4j13O1J6dggGz1yEUjin//mZZWts6qNU9S8ytbX7bHiN22Iu0olCgstsXtO1H QaKA== 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 d17si2825282oij.136.2020.02.12.03.21.14; Wed, 12 Feb 2020 03:21:30 -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 S1728021AbgBLLTw (ORCPT + 99 others); Wed, 12 Feb 2020 06:19:52 -0500 Received: from 8bytes.org ([81.169.241.247]:53636 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727947AbgBLLTv (ORCPT ); Wed, 12 Feb 2020 06:19:51 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 50C2B4A6; Wed, 12 Feb 2020 12:19:49 +0100 (CET) Date: Wed, 12 Feb 2020 12:19:24 +0100 From: Joerg Roedel To: Andy Lutomirski Cc: X86 ML , "H. Peter Anvin" , Dave Hansen , Peter Zijlstra , Thomas Hellstrom , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , LKML , kvm list , Linux Virtualization , Joerg Roedel Subject: Re: [PATCH 08/62] x86/boot/compressed/64: Add IDT Infrastructure Message-ID: <20200212111923.GA20066@8bytes.org> References: <20200211135256.24617-1-joro@8bytes.org> <20200211135256.24617-9-joro@8bytes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Hi Andy, thanks a lot for your valuable reviews! On Tue, Feb 11, 2020 at 02:18:52PM -0800, Andy Lutomirski wrote: > On Tue, Feb 11, 2020 at 5:53 AM Joerg Roedel wrote: > > + entry.offset_low = (u16)(address & 0xffff); > > + entry.segment = __KERNEL_CS; > > + entry.bits.type = GATE_TRAP; > > ^^^ > > I realize we're not running a real kernel here, but GATE_TRAP is > madness. Please use GATE_INTERRUPT. Changed that. > > + /* Build pt_regs */ > > + .if \error_code == 0 > > + pushq $0 > > + .endif > > cld Added. > > + popq %rdi > > if error_code? The code above pushes a $0 for exceptions without an error code, so it needs to be removed unconditionally. > > + > > + /* Remove error code and return */ > > + 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) > > + > > If this actually happens, you have a major bug. Please sanitize all > the segment registers after installing the GDT rather than hacking > around it here. Okay, will change that. I thought I could safe some instructions in the head_64.S code, but you are right that its better to setup a defined environment first. Thanks, Joerg