Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp880857imm; Wed, 11 Jul 2018 12:38:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfhTt5h+lgipXZpKyMqnUERc6iCsB3YE9gSihMG4Dcg1kUmGrRKO/HeUVYgsGU0JZChwla7 X-Received: by 2002:a17:902:68:: with SMTP id 95-v6mr29942592pla.178.1531337890779; Wed, 11 Jul 2018 12:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531337890; cv=none; d=google.com; s=arc-20160816; b=AecPwUmaAaPOToLXbgu/F6ya4P012/7YgjjyD4wHpJrF46r9XjelCvxdFkQ+rtCp/c PFT01qTJvtuEAd0zLHup6kYlL05E0diyrJXDY/R8Ol92sjf0NxkCNW0QvzRK+FsfCFGg EbAZjJehORO8q1cvItUVu7nQcsrbU5QW6FRs++ftVVXGxNhAdHEX4rRdMtc1c98U0vxd xMbV1fOxiY6RZ0GbXCCVGn9B2YXQSUEPf4XYTRektqIv9wXkkE7FQoZEL29myUNL3Pur DJ8y5QXnzpDSZ4iTe9yV175r2qV94CY8+VxLB6siA76N2a/UPLUqlKdPVQE0TbyTGO5n v3dw== 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:mime-version :references:in-reply-to:date:to:from:subject:message-id :arc-authentication-results; bh=DqfzsaZn46RPb7qrcXF2mlWJGUibyNosXHQj8oMcATE=; b=y0mMgZ8zDvl/QUsR251Ye00POnBGdVMMYsdz1aEcHI+5SWuwT7bvLa8BEfU6euGBD5 3HhoImIOu04pZ+O0aWnYpkQ3bd+tPNXRBUJQUszWpPClP6kzmJ5zDDfVxqdPnnJ6iprD WlMuA/nOYSCtlgSehgsWJVMFjoIRcGbid76iPHDs/XmXeZa5hFqFccfZoct5XaRSW+FD AAzwfxu1V+pHwIoPOcqaU063gW1PhC3qDKl/A4caWdGVgush8Z4b4zcVXN5C7cwOyDU1 +WL4KYxSMBLNsbZqGbRX1t6zvck22PVWylGk704nTX+/0aOMpTQtE1S1yRWcFYpP7YTg vroQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j67-v6si5013960pfg.34.2018.07.11.12.37.54; Wed, 11 Jul 2018 12:38:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390095AbeGKRP5 (ORCPT + 99 others); Wed, 11 Jul 2018 13:15:57 -0400 Received: from mga11.intel.com ([192.55.52.93]:42644 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388700AbeGKRP5 (ORCPT ); Wed, 11 Jul 2018 13:15:57 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jul 2018 10:10:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,338,1526367600"; d="scan'208";a="56885705" Received: from 2b52.sc.intel.com ([143.183.136.52]) by orsmga006.jf.intel.com with ESMTP; 11 Jul 2018 10:09:08 -0700 Message-ID: <1531328731.15351.3.camel@intel.com> Subject: Re: [RFC PATCH v2 16/27] mm: Modify can_follow_write_pte/pmd for shadow stack From: Yu-cheng Yu To: Dave Hansen , 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 , Peter Zijlstra , "Ravi V. Shankar" , Vedvyas Shanbhogue Date: Wed, 11 Jul 2018 10:05:31 -0700 In-Reply-To: References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-17-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-07-10 at 16:37 -0700, Dave Hansen wrote: > On 07/10/2018 03:26 PM, Yu-cheng Yu wrote: > > > > There are three possible shadow stack PTE settings: > > > >   Normal SHSTK PTE: (R/O + DIRTY_HW) > >   SHSTK PTE COW'ed: (R/O + DIRTY_HW) > >   SHSTK PTE shared as R/O data: (R/O + DIRTY_SW) > > > > Update can_follow_write_pte/pmd for the shadow stack. > First of all, thanks for the excellent patch headers.  It's nice to > have > that reference every time even though it's repeated. > > > > > -static inline bool can_follow_write_pte(pte_t pte, unsigned int > > flags) > > +static inline bool can_follow_write_pte(pte_t pte, unsigned int > > flags, > > + bool shstk) > >  { > > + bool pte_cowed = shstk ? is_shstk_pte(pte):pte_dirty(pte); > > + > >   return pte_write(pte) || > > - ((flags & FOLL_FORCE) && (flags & FOLL_COW) && > > pte_dirty(pte)); > > + ((flags & FOLL_FORCE) && (flags & FOLL_COW) && > > pte_cowed); > >  } > Can we just pass the VMA in here?  This use is OK-ish, but I > generally > detest true/false function arguments because you can't tell what they > are when they show up without a named variable. > > But...  Why does this even matter?  Your own example showed that all > shadowstack PTEs have either DIRTY_HW or DIRTY_SW set, and > pte_dirty() > checks both. > > That makes this check seem a bit superfluous. My understanding is that we don't want to follow write pte if the page is shared as read-only.  For a SHSTK page, that is (R/O + DIRTY_SW), which means the SHSTK page has not been COW'ed.  Is that right? Thanks, Yu-cheng