Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp848043ybg; Tue, 28 Jul 2020 22:20:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8MEIDF8WxW1PAnfSW0VTNtw0VlIXjDrI8qISqKPIYMs/3y1zVGmHJBMgvfwqNT+Krc4gR X-Received: by 2002:a17:906:80d3:: with SMTP id a19mr29865061ejx.217.1596000028332; Tue, 28 Jul 2020 22:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596000028; cv=none; d=google.com; s=arc-20160816; b=dkpQ8faDVggHjS1YxhVzj6wB10VS5mlpLHTJ6EKbbHRig176GI1axUd/zTby/K5D3g 30yzhna50VG79I+kWptCeWRBerrQ3xr1TpiTYyomH0GHthX6EE24/hOUyjYaSSJh/VYm SuXFj9DiEC1G1osUAilMsOnZkl4Xka1kNlJFu7+C89ONdJZTDeqVDveHy5tJU1akjow4 9TDT516IuIBWc4I5NFDa/xPCDlsETgLr9P0Z35vIGIrEaU705V4sZssWOcW2WH98rQ5h PRED941oUhEFSCUMhs3hagGpWkwjIzfkcXR0L1j4Xjn3czxstWfzydRdg0SE/QPcKexP DQYQ== 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 :in-reply-to:references:mime-version:dkim-signature; bh=2UKkCu/akWQF3Phhmv0BjohogZZWipvB0TXay9YwQBo=; b=Q93xerkibINIYlLAHOrBHkpdmlhjTVws/7y5Vl4eK9A7mcmV+Fww7ad1AGxwpesXUM jo7E7hNa3igZ/Sb0b7EOdG/UaFa2JuCXM5c1ZBgJOEPz/rPgKB6P5bjb673VcnU/MIjR YaBKEj3eMHS2VrUh9UGA0I29IaK2APvUqfpUz/wbNQ1KDWa7QTa+sAtvWNzP1Yqq5S/T fN5neAtUNDOjnmO5YJXo7kaTRJrkwTdLLa2xtgb950Q2nLIQ7h92v8rXC8VWpu+rVy6S 8IvsPS94za1MZ12IGKqErLrb+I0uD2XOseMkmdIQe7b1ny77iYtxw9PFYH8s1V4/JqEo 2jwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="k2/ypYf8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j20si584126edr.321.2020.07.28.22.20.06; Tue, 28 Jul 2020 22:20:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="k2/ypYf8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726933AbgG2FRA (ORCPT + 99 others); Wed, 29 Jul 2020 01:17:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:47524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726880AbgG2FQ7 (ORCPT ); Wed, 29 Jul 2020 01:16:59 -0400 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E826621D95 for ; Wed, 29 Jul 2020 05:16:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595999819; bh=qItqwNi4q4ELXpJAVlv3H8dC/ihmulIDrwoa1DDcrFY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=k2/ypYf8chH29waA/oS7FzUjhmqJvZsAK5yreLc+JnHHzlqaz9vnEqabE+qyemEMh V59mmT0x99Zz7xAAr4mzDnLpnXyxu10GUK80PkfmZzTfRw0ApQRzkJVmfxPNtOL+Nt orHtR8IzwwnOF1rKVTvLOZzzbUFBmX6T//Qhyjrc= Received: by mail-wm1-f44.google.com with SMTP id k20so1616288wmi.5 for ; Tue, 28 Jul 2020 22:16:58 -0700 (PDT) X-Gm-Message-State: AOAM532/KXNbuw+hurbZhkrbVJ/u2gH0qJTnXCyEKRMT2vIbul15Hn2y 6FX878u4o3WwvOW1N33ZGQHvu+dGbjchYfPsljh74g== X-Received: by 2002:a1c:7511:: with SMTP id o17mr7308351wmc.49.1595999817430; Tue, 28 Jul 2020 22:16:57 -0700 (PDT) MIME-Version: 1.0 References: <20200728131050.24443-1-madvenka@linux.microsoft.com> <81d744c0-923e-35ad-6063-8b186f6a153c@linux.microsoft.com> In-Reply-To: <81d744c0-923e-35ad-6063-8b186f6a153c@linux.microsoft.com> From: Andy Lutomirski Date: Tue, 28 Jul 2020 22:16:45 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 0/4] [RFC] Implement Trampoline File Descriptor To: "Madhavan T. Venkataraman" Cc: Andy Lutomirski , David Laight , "kernel-hardening@lists.openwall.com" , "linux-api@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-fsdevel@vger.kernel.org" , "linux-integrity@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-security-module@vger.kernel.org" , "oleg@redhat.com" , "x86@kernel.org" 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 Tue, Jul 28, 2020 at 10:40 AM Madhavan T. Venkataraman wrote: > > > > On 7/28/20 12:16 PM, Andy Lutomirski wrote: > > On Tue, Jul 28, 2020 at 9:32 AM Madhavan T. Venkataraman > wrote: > > Thanks. See inline.. > > On 7/28/20 10:13 AM, David Laight wrote: > > From: madvenka@linux.microsoft.com > > Sent: 28 July 2020 14:11 > > ... > > The kernel creates the trampoline mapping without any permissions. When > the trampoline is executed by user code, a page fault happens and the > kernel gets control. The kernel recognizes that this is a trampoline > invocation. It sets up the user registers based on the specified > register context, and/or pushes values on the user stack based on the > specified stack context, and sets the user PC to the requested target > PC. When the kernel returns, execution continues at the target PC. > So, the kernel does the work of the trampoline on behalf of the > application. > > Isn't the performance of this going to be horrid? > > It takes about the same amount of time as getpid(). So, it is > one quick trip into the kernel. I expect that applications will > typically not care about this extra overhead as long as > they are able to run. > > What did you test this on? A page fault on any modern x86_64 system > is much, much, much, much slower than a syscall. > > > I tested it in on a KVM guest running Ubuntu. So, when you say > that a page fault is much slower, do you mean a regular page > fault that is handled through the VM layer? Here is the relevant code > in do_user_addr_fault(): I mean that x86 CPUs have reasonably SYSCALL and SYSRET instructions (the former is used for 64-bit system calls on Linux and the latter is mostly used to return from system calls), but hardware page fault delivery and IRET (used to return from page faults) are very slow.