Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp275490imm; Wed, 11 Jul 2018 02:08:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcF3gOyN6cPr6tjsbmckHhIcV3sSQnf3aUMA+/qvYuoCvFKfmVuR0+W6HHzUpsI8d8VnjfW X-Received: by 2002:a63:9741:: with SMTP id d1-v6mr25238367pgo.403.1531300123093; Wed, 11 Jul 2018 02:08:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531300123; cv=none; d=google.com; s=arc-20160816; b=B9s3mcO6GM87mZ4g3/e+CZZYQu0N6wX/NNqLtzW1aUkbw4ZMtAeL3N8HqDNLfmJMRx 6kh+8Ib4Ka3xULRhx/jrQcYyGmYhHhgUlUTYEoFMfgChYc74nDAyOuso77l2PuF29xWV r6+p0oE7q2ug79Cq/0BhuHXhZICtUJFVBH65qOzPfPCv8Hct+bhj6zN6ddwrhK8Q76bN 4afxzroI4XBQcuhQZS/DD6XX82ieyujIYoeeN4SQAwer4LMV/q/qkqqMTSVm7tTv1Z0H vG1EMKEevBp1hJC9jXn74dRRU/F/WFfuEh1RxU1fit7HTj6ynKxxlS4DhdyJXIhLF+cx U4cA== 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:dkim-signature:arc-authentication-results; bh=InLvEauMwcKvCxwW7K7Ux/s6fcMp9nd2FM12RUuHvGA=; b=Zf9aC0MFpCqFGvY96gv5EJOgpapdAVy9JiOxQKIhovhaPrtNzqdJR4CcAoC1RYcVp7 AdTOsixBQVgZt2Q+4lIW4B7lf1De/JF0kyjBbKEL+IhoPMrv9NH1InREh+UEgfzKJsGw Nc8Bf9gSEt/unx52YjXN9nANHFiaMHFm9gl7J49riUWS7mT6YFO3eXNX7UweVSG3/VEP F1NGbCMiYR459U1FWJGdONIcAZHlJ3SnoyUSf7jl7IkRWDoIrUPnWoSMZGSbW3UAcajJ Vstr0gDBJfcVmZxqVyK9zFRvE5+7EyF7UDSCuhoPchL4nsSGD9Nmim+K3hix3bNLDCAl yB3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=CJHCd0Hy; 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 d11-v6si18382066pla.184.2018.07.11.02.08.25; Wed, 11 Jul 2018 02:08:43 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=CJHCd0Hy; 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 S1732419AbeGKJKX (ORCPT + 99 others); Wed, 11 Jul 2018 05:10:23 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58432 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726335AbeGKJKX (ORCPT ); Wed, 11 Jul 2018 05:10:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=InLvEauMwcKvCxwW7K7Ux/s6fcMp9nd2FM12RUuHvGA=; b=CJHCd0HyEzyV40AQcyX7Uazq+ ELRox0LV1q9cona1HliZfS6vQxIeadKugqvOwDqbSVCL71ld31RMKEHsQMQslDRM0DbNnm2/mndOf 4mlSN2PXd4MPRWWTok5UjPWfRfCOl4IuSyALUn850hWwLrGPxklddwPezUT1b08r2GU5n2bwTTPds DX8sw9e8p26no3K9YqpcWWzIts41zwq/y+2t9U9eOU4C+zLeyO7fck0bKfnYfI5EBT0Z/AHAGXsA5 jhtE4OLU2Z3KgC+OAX5DuzdSrQk+Bgu7/CzxwB58zaVXeLYzoBn7iLFfo4UVmE+tFbY8P4jzRveIz SsK0hiDXw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdB5N-0002lX-VE; Wed, 11 Jul 2018 09:06:58 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 72D7820291063; Wed, 11 Jul 2018 11:06:56 +0200 (CEST) Date: Wed, 11 Jul 2018 11:06:56 +0200 From: Peter Zijlstra To: Dave Hansen Cc: Yu-cheng Yu , x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , "Ravi V. Shankar" , Vedvyas Shanbhogue Subject: Re: [RFC PATCH v2 13/27] mm: Handle shadow stack page fault Message-ID: <20180711090656.GS2476@hirez.programming.kicks-ass.net> References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-14-yu-cheng.yu@intel.com> <2f3ff321-c629-3e00-59f6-8bca510650d4@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2f3ff321-c629-3e00-59f6-8bca510650d4@linux.intel.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 10, 2018 at 04:06:25PM -0700, Dave Hansen wrote: > On 07/10/2018 03:26 PM, Yu-cheng Yu wrote: > > + if (is_shstk_mapping(vma->vm_flags)) > > + entry = pte_mkdirty_shstk(entry); > > + else > > + entry = pte_mkdirty(entry); > > + > > + entry = maybe_mkwrite(entry, vma); > > if (ptep_set_access_flags(vma, vmf->address, vmf->pte, entry, 1)) > > update_mmu_cache(vma, vmf->address, vmf->pte); > > pte_unmap_unlock(vmf->pte, vmf->ptl); > > @@ -2526,7 +2532,11 @@ static int wp_page_copy(struct vm_fault *vmf) > > } > > flush_cache_page(vma, vmf->address, pte_pfn(vmf->orig_pte)); > > entry = mk_pte(new_page, vma->vm_page_prot); > > - entry = maybe_mkwrite(pte_mkdirty(entry), vma); > > + if (is_shstk_mapping(vma->vm_flags)) > > + entry = pte_mkdirty_shstk(entry); > > + else > > + entry = pte_mkdirty(entry); > > + entry = maybe_mkwrite(entry, vma); > > Do we want to lift this hunk of code and put it elsewhere? Maybe: > > entry = pte_set_vma_features(entry, vma); > > and then: > > pte_t pte_set_vma_features(pte_t entry, struct vm_area_struct) > { > /* > * Shadow stack PTEs are always dirty and always > * writable. They have a different encoding for > * this than normal PTEs, though. > */ > if (is_shstk_mapping(vma->vm_flags)) > entry = pte_mkdirty_shstk(entry); > else > entry = pte_mkdirty(entry); > > entry = maybe_mkwrite(entry, vma); > > return entry; > } Yes, that wants a helper like that. Not sold on the name, but whatever. Is there any way we can hide all the shadow stack magic in arch code?