Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp568259ybg; Tue, 28 Jul 2020 13:02:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHuhsi7f/5u/otvjXdDJPQpANS3Tj4C4thPTxtnjWaDD80mXWI0MFOSFHk3EUrjWepVd0Q X-Received: by 2002:a17:906:cc4d:: with SMTP id mm13mr15325460ejb.191.1595966550461; Tue, 28 Jul 2020 13:02:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595966550; cv=none; d=google.com; s=arc-20160816; b=pgkKbOGnRyGSdmpz6V02lw9CN+GUJclZCgfFw07zHxWSvXfUZicbiN2w9D5rSLJ3QP G3exceakPmC35lkxFzHFdIBaK5LNY1BFnmGKqdXCnpFUkE+srJRJWd8C70hK6NoyqDnC Uo3QEoI1k+4kz9ViWeZHPEXHxbddYrlGjY0c+ETL98Jnm3hVWpbkZRrH20y/YjerAFpC G7wNGVdiF1nH2XuMSm0iFqgLXYLC6n9fq/69dnzUpGpjOtLko/dnD3biQWEL/bz+aR1y RCWBLGEUqQcjZ7E8P3uWl9wS8v8RqQAQCBGZsavE7WFhccimT6fPGEPbdyClUL9eqLKq CwCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature:dkim-filter; bh=4VqGIlTMQb0KmRbW1ECdJsuWGdo+ykQfeo4qSABGj8g=; b=a8ZSz8luQzIpgyLbtWHALU9zB70+9doCjqYrje2P9KdUui+BI5Rp+yOEhTbRyiizvr M/6q5vnFhpmv3GsPtNpouyI5LoJ8agWHjR0onQRyUPj0eaev8RvucW520al00E6W5b5N PGnc0NqXHJR9nBiS6KB6jo4ayW+o14BoUSXmZ4kgBiLjtVnhufZYa4S54sXq3ohtLrnN du+9Rm4zdVxTrNA4IcXdflx3RV2/xpGyu3G1Iwl3RyabHyc5GGQorcPnZTa+19zn2MOn TgUyUhTPNK0VcIe8PhTgb9YCjDOUwSa89cEwGrVDwzNeVkupIHtj+QR/52CMZi7eSoY5 LrWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=N5ASgrJb; 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=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si7943271ejb.273.2020.07.28.13.02.08; Tue, 28 Jul 2020 13:02:30 -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=@linux.microsoft.com header.s=default header.b=N5ASgrJb; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732518AbgG1SwE (ORCPT + 99 others); Tue, 28 Jul 2020 14:52:04 -0400 Received: from linux.microsoft.com ([13.77.154.182]:54666 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728782AbgG1SwE (ORCPT ); Tue, 28 Jul 2020 14:52:04 -0400 Received: from [192.168.254.32] (unknown [47.187.206.220]) by linux.microsoft.com (Postfix) with ESMTPSA id D9CA720B4908; Tue, 28 Jul 2020 11:52:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D9CA720B4908 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1595962323; bh=4VqGIlTMQb0KmRbW1ECdJsuWGdo+ykQfeo4qSABGj8g=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=N5ASgrJbpo8ewcnejqNlOMHW1LlvWw6Pa2UCzET1NHRPpRnwTSki0Dk44+lBNhwyc 0Oczcbp+TB0JMzyxyK22fLDJcHQra90UOmtWziVf9oqC+T8MJc1Dn+vnJuvj0FVugv h+6UG1h/10vIpOjMBqWpPTkZqsk7ZujJKLdE1AKo= Subject: Re: [PATCH v1 0/4] [RFC] Implement Trampoline File Descriptor To: Andy Lutomirski Cc: 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" References: <20200728131050.24443-1-madvenka@linux.microsoft.com> From: "Madhavan T. Venkataraman" Message-ID: <59246260-e535-a9f1-d89e-4e953288b977@linux.microsoft.com> Date: Tue, 28 Jul 2020 13:52:01 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 sent a response to this. But the mail was returned to me. I am resending. 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():         if (unlikely(access_error(hw_error_code, vma))) {                 /*                                   * If it is a user execute fault, it could be a trampoline                  * invocation.                  */                 if ((hw_error_code & tflags) == tflags &&                      trampfd_fault(vma, regs)) {                          up_read(&mm->mmap_sem);                          return;                  }                  bad_area_access_error(regs, hw_error_code, address, vma);                  return;          }          ...          fault = handle_mm_fault(vma, address, flags); trampfd faults are instruction faults that go through a different code path than the one that calls handle_mm_fault(). Perhaps, it is the handle_mm_fault() that is time consuming. Could you clarify? Thanks. Madhavan