Received: by 10.223.185.116 with SMTP id b49csp3017818wrg; Mon, 5 Mar 2018 12:33:07 -0800 (PST) X-Google-Smtp-Source: AG47ELvocSU8Lci7vEfSgn5ZdwoGaN1ZOTi1yYz/HJEABMlCxi8q91pnysmHC4BdGB0TbJjxg8jv X-Received: by 2002:a17:902:1486:: with SMTP id k6-v6mr14650647pla.376.1520281987795; Mon, 05 Mar 2018 12:33:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520281987; cv=none; d=google.com; s=arc-20160816; b=RKiyHlMzFIJx/yFpHE120N0LM/yOCXlMollTjlvlDUukai5uQ++KiBhAEqAzEmzyJd nCMnqbFtRkrtOQdTqIdpo31iF0tONleCmlO7vjlTPVIfEuUbuHoetPv/cuSSINST7Wqz I7g0lhUODjbaGPjFRrPasog9a9Jki1RTj9D8K8M/2YkfI8AUCvUOIAXzC5gpR3Jt6wm7 x3oni1dJI6k+SGk6WR84Gi4FIrNFCF427rmTTmQczhQMTDImBB+9TD85T+A+ifxtgXbL jNCKzk5n0f4f/w1qV4yBUA/7eNmDMpOj/9EZZsgh0qdwRXxGn3wq5WORpibAUqmnZMX0 Kt5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=GCFX45c8zG1KkZpnQTpg2sNnK3mgriY+rxRHJ3D/eYI=; b=V+MLriioP3zy+3SKAKX1MozQd1J5iU6iYZhdW+IpbvQnqAeKfqN33D0g0TSE5WrY5L L218nmwKRyigX7hNplnwQFrICa8kv8U0pUub4cDAeJJGcXx6pWqU9FPZbF9LG1ejC/ha DlcQZ/P5awjaTOISXyVKsuqWo5k/5AW5xBhgYNFEueL0UuY5YlT0XdwgDxCMk2rApqWm S1fjuGdbPc3rDhsfsaLk/yuYrB48iAEoE0sYtMqo1fiO/xs2Xkb2Suljv6OoktxqAtHy 3+3EHc4hAfOWscc9nu+Y40s+IkUsPJbxRaI5LqholwgFJyDlm8dJPmgSD/8Uti3Bmu+K +yPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ShlmOkuQ; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si8745046pge.307.2018.03.05.12.32.53; Mon, 05 Mar 2018 12:33:07 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ShlmOkuQ; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752995AbeCEUcE (ORCPT + 99 others); Mon, 5 Mar 2018 15:32:04 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:39464 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752931AbeCEUcC (ORCPT ); Mon, 5 Mar 2018 15:32:02 -0500 Received: by mail-it0-f66.google.com with SMTP id l187so11822808ith.4 for ; Mon, 05 Mar 2018 12:32:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=GCFX45c8zG1KkZpnQTpg2sNnK3mgriY+rxRHJ3D/eYI=; b=ShlmOkuQXtv5D/rGXfChm2ZgVYEmq0jWW9ASr8lye3rRrmx35flCC2pALvuwYJYqI7 YuvXaEdZ4lNAoXy/UKO1QKWPnXwv9kBz4Ek20HsWjXm1qfg2u+h6F9uql0eaz+4Cj56d QctVAu6Cy28f4zingn0xVBDSz/usxT8DrmEVYrbvkUIXdJeRclaZLNbSU1k7/AOBz2hT sTOmRcVhtTweCUmTAVbUxpW7Oc4W3aGWx0xiXVxqYjYI6/1cKS5XrPmbzb3xDR+W7Z0p hdOTeSw9NvcBmJO538siP/JjCnUG9BsBDxR7sF6xCB54pjh8RgLdxMgPGhaSQ0adCW+W lbIQ== 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; bh=GCFX45c8zG1KkZpnQTpg2sNnK3mgriY+rxRHJ3D/eYI=; b=SOq9zRhQGjnsQcwB3O1cMH2MCk8DzA8MvzncInC11LHHPZjDYLpCY4tzDFNANDYjLI TGb6DkxifLQoJMqoy3Bsjrvm1fD9LnZLE9LgUD+y2qu0QmGhDhrhtH3XDSAXWH0ZQ7bY orvQcTEqf1zo4WEvgBLZbLz0Hy3rIk55dmyPjdGx4kP5ctl4TFuVIIvyw4Q45HO2DrrD aKuYcFNnpfOH8uRCDXg469PrTZoRD1ImTpcwH9xABI7O8AJHdIyhkMlp2ZwmBvPrC24G 3a3JXD7q6i6EOzMrPqWx0QicsEHHGGOAalmVSJk2wJ8CV+H529b+HmM5JJrzVvXmmcLH /bMA== X-Gm-Message-State: AElRT7HZo0dK6a20z64A6T80CL5JXBIQp+YLjlk2p6eZs0Xuqc97+QBp PlM/oRdCZBmvVPYf53n0uqSeFoHIWzAEwSZCpg== X-Received: by 10.36.208.4 with SMTP id m4mr16558317itg.69.1520281921631; Mon, 05 Mar 2018 12:32:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.118.212 with HTTP; Mon, 5 Mar 2018 12:32:01 -0800 (PST) In-Reply-To: <20180305182524.GT16484@8bytes.org> References: <1520245563-8444-1-git-send-email-joro@8bytes.org> <1520245563-8444-12-git-send-email-joro@8bytes.org> <20180305182524.GT16484@8bytes.org> From: Brian Gerst Date: Mon, 5 Mar 2018 15:32:01 -0500 Message-ID: Subject: Re: [PATCH 11/34] x86/entry/32: Handle Entry from Kernel-Mode on Entry-Stack To: Joerg Roedel Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , "the arch/x86 maintainers" , Linux Kernel Mailing List , Linux-MM , Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , "Liguori, Anthony" , Daniel Gruss , Hugh Dickins , Kees Cook , Andrea Arcangeli , Waiman Long , Pavel Machek , Joerg Roedel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 5, 2018 at 1:25 PM, Joerg Roedel wrote: > Hi Brian, > > thanks for your review and helpful input. > > On Mon, Mar 05, 2018 at 11:41:01AM -0500, Brian Gerst wrote: >> On Mon, Mar 5, 2018 at 5:25 AM, Joerg Roedel wrote: >> > +.Lentry_from_kernel_\@: >> > + >> > + /* >> > + * This handles the case when we enter the kernel from >> > + * kernel-mode and %esp points to the entry-stack. When this >> > + * happens we need to switch to the task-stack to run C code, >> > + * but switch back to the entry-stack again when we approach >> > + * iret and return to the interrupted code-path. This usually >> > + * happens when we hit an exception while restoring user-space >> > + * segment registers on the way back to user-space. >> > + * >> > + * When we switch to the task-stack here, we can't trust the >> > + * contents of the entry-stack anymore, as the exception handler >> > + * might be scheduled out or moved to another CPU. Therefore we >> > + * copy the complete entry-stack to the task-stack and set a >> > + * marker in the iret-frame (bit 31 of the CS dword) to detect >> > + * what we've done on the iret path. >> >> We don't need to worry about preemption changing the entry stack. The >> faults that IRET or segment loads can generate just run the exception >> fixup handler and return. Interrupts were disabled when the fault >> occurred, so the kernel cannot be preempted. The other case to watch >> is #DB on SYSENTER, but that simply returns and doesn't sleep either. >> >> We can keep the same process as the existing debug/NMI handlers - >> leave the current exception pt_regs on the entry stack and just switch >> to the task stack for the call to the handler. Then switch back to >> the entry stack and continue. No copying needed. > > Okay, I'll look into that. Will it even be true for fully preemptible > and RT kernels that there can't be any preemption of these handlers? See resume_kernel in the 32-bit entry for how preemption is handled on return to kernel mode. Looking at the RT patches, they still respect disabling interrupts also disabling preemption. -- Brian Gerst