Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp21435imm; Tue, 17 Jul 2018 13:08:53 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf5kleypZf0REnLwv670W08gRohbnE7sHlKsS3SeBDyKAl/yZIekLVBAtEfjA640pajUX9k X-Received: by 2002:a17:902:26c:: with SMTP id 99-v6mr2897944plc.341.1531858133359; Tue, 17 Jul 2018 13:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531858133; cv=none; d=google.com; s=arc-20160816; b=Rl6VMq3Gb9kdM56unvLHPgYk8YOLOm+IhWv9QuJ5qUgra5VVZX0aQ79X3TtCpOCTW6 5b8wzLI5M4YuCTStqe+XMC6k5f/MZKMWy+DKUYI1CfcERcfB0zRRpWZMVG2/VWfJoAs/ j0prI831/TWeGQrySSflvzrL6v465Dhxhz4zraQ0WfF7hOvQAQHgVo2stMCq9BF5+wU5 q4qXEUrtv3s+SOL68DNTRGQqPZaaglnOWOIRNpm+/SBhBL4h7BU0Lbdkw5HBFw1ZIeB6 vZbQN1gqxa6Nh+1EzV5qUxHAszJAEiKcmklTA686U2j9dKlhOjcZ72bu8HT/AG8Rkj+e NXgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=DfXPsxu1Dp+K/Kc47BnLwyrteW3/d+HDwDVopLlRgH8=; b=Cukr8eRCKIQgTKnesaP5VYtDt6d+z1BPB6wMfpPG86wXUL6Qv8L5YpYilfPEiLKg4U pYngDrfOVpBV6uq/czu+r0nTB6Xih5CCkGCCYh3AWCkQ7iEMZygViVPN3fQsXNnFwMiX p7CgnyjrhcaUeI9GZ+CwqjlgWPCkjFU2PSozUEgzrIdh0aChTp88Q/HHM3pjEDF771vf FQORGVQEwAx6V92Gxbt+X6CNO6uLpuXq7cDQeKiGLEljBuKc/9megoluO730bd8cTrGE 0wcQNwLOki1O8pIaGySSug3jyaYwtKnViUWWPXqsf7AuD/pJGunxKx4n2rpl9I38cJg2 FGHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=TeaxKs0z; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9-v6si1487859pgu.636.2018.07.17.13.08.35; Tue, 17 Jul 2018 13:08:53 -0700 (PDT) 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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=TeaxKs0z; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730667AbeGQUkr (ORCPT + 99 others); Tue, 17 Jul 2018 16:40:47 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34826 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729838AbeGQUkq (ORCPT ); Tue, 17 Jul 2018 16:40:46 -0400 Received: by mail-wr1-f65.google.com with SMTP id a3-v6so2415988wrt.2 for ; Tue, 17 Jul 2018 13:06:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=DfXPsxu1Dp+K/Kc47BnLwyrteW3/d+HDwDVopLlRgH8=; b=TeaxKs0zj4BRUUojh/t9lYaUcq3v6ZTpuqlEOQmOL4t9oImO2JAFN8WRYfgpm4MD/l QG6CS5nrKnr+1IiZBuo1WZy8vfN8yIgN8gx64DOVdeSgO7DWpf68KPb6f1zN4WLirXDh bmXkWbopDPKodDDjFfti8IpB3VUjYeKzq6n1MAum+OTvhd16MAt550wHva/BJkv9kOoi BGyayato2VUfu4WG1oIEBpenV0if/owXrm2V18A4lnLSSUAIoKeS2KxRfeCBJ4indEPr rQNiKQqs4/B13usiPwF9jYt/MWtCt+gHATUuMmycirQRwwzrORDXL+failMcjVffFcI+ iG4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=DfXPsxu1Dp+K/Kc47BnLwyrteW3/d+HDwDVopLlRgH8=; b=C33Uju7XTsLtWpitkGIO/kYOGH+akVcAXSR4Mq3ZrKAvzdOQgdWFx85X3prUm39i4w sfNAfJVMjC0fpp8yP0w3/IEXDM8qZfDP9lzHzS3lQ09NpoUmwKgEI3ZPfV8VDxYWMtCu z89Axb0nNWC7sYJx5lIX4ui2gji6s3j0Z2S3ueHP8IKPE+sNKeKQkoHQLI3bR89vdj+B c3xPtjB7o8Rl4P+LsM0TFXwcSzshDzLvqdrrKMk9ZxHV4YQdZ+p6c/NtxqnebiNitnv5 ymMNCYkclyJUww4ES6GDdIi4bfMp3ryfSVgcN7DUARhY5iYSCFFboY7t2FB9RSWuiTH6 YMHQ== X-Gm-Message-State: AOUpUlHJog1Kp0D+3CWRq5vnUtio2HXGgScrMqOJa8YQ6+1nvchpbeIF 8xI9Pp4bsgxOGleGQFdnmbrhyauXhNMOKy+GIbytVw== X-Received: by 2002:adf:fe42:: with SMTP id m2-v6mr2273311wrs.171.1531857991713; Tue, 17 Jul 2018 13:06:31 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:d548:0:0:0:0:0 with HTTP; Tue, 17 Jul 2018 13:06:11 -0700 (PDT) In-Reply-To: <20180717071545.ojdall7tatbjtfai@suse.de> References: <1531308586-29340-1-git-send-email-joro@8bytes.org> <1531308586-29340-11-git-send-email-joro@8bytes.org> <20180714052110.cobtew6rms23ih37@suse.de> <7AB4F269-E0E8-4290-A764-69D8605467E8@amacapital.net> <20180714080159.hqp36q7fxzb2ktlq@suse.de> <75BDF04F-9585-438C-AE04-918FBE00A174@amacapital.net> <20180717071545.ojdall7tatbjtfai@suse.de> From: Andy Lutomirski Date: Tue, 17 Jul 2018 13:06:11 -0700 Message-ID: Subject: Re: [PATCH 10/39] x86/entry/32: Handle Entry from Kernel-Mode on Entry-Stack To: Joerg Roedel Cc: Andy Lutomirski , Joerg Roedel , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , X86 ML , LKML , Linux-MM , Linus Torvalds , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , "Liguori, Anthony" , Daniel Gruss , Hugh Dickins , Kees Cook , Andrea Arcangeli , Waiman Long , Pavel Machek , "David H . Gutteridge" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 12:15 AM, Joerg Roedel wrote: > On Sat, Jul 14, 2018 at 07:36:47AM -0700, Andy Lutomirski wrote: >> But I=E2=80=99m still unconvinced. If any code executed with IRQs enable= d on >> the entry stack, then that code is terminally buggy. If you=E2=80=99re >> executing with IRQs off, you=E2=80=99re not going to get migrated. 64-b= it >> kernels run on percpu stacks all the time, and it=E2=80=99s not a proble= m. > > The code switches to the kernel-stack and kernel-cr3 and just remembers > where it came from (to handle the entry-from-kernel with entry-stack > and/or user-cr3 case). IRQs are disabled in the entry-code path. But > ultimately it calls into C code to handle the exception. And there IRQs > might get enabled again. > >> IRET errors are genuinely special and, if they=E2=80=99re causing a prob= lem >> for you, we should fix them the same way we deal with them on x86_64. > > Right, IRET is handled differently and doesn't need this patch. But the > segment-writing exceptions do. > > If you insist on it I can try to implement the assumption that we don't > get preempted in this code-path. That will safe us some cycles for > copying stack contents in this unlikely slow-path. But we definitly need > to handle the entry-from-kernel with entry-stack and/or user-cr3 case > correctly and make a switch to kernel-stack/cr3 because we are going to > call into C-code. > > Yes, we obviously need to restore the correct cr3. But I really don't like the code that rewrites the stack frame that we're about to IRET to, especially when it doesn't seem to serve a purpose. I'd much rather the code just get its CR3 right and do the IRET and trust that the frame it's returning to is still there.