From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E26C7C433ED for ; Fri, 23 Apr 2021 10:25:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2FD56145F for ; Fri, 23 Apr 2021 10:25:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241999AbhDWK0F (ORCPT ); Fri, 23 Apr 2021 06:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbhDWKZ7 (ORCPT ); Fri, 23 Apr 2021 06:25:59 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EBABC061574 for ; Fri, 23 Apr 2021 03:25:23 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id b38so14011393ljf.5 for ; Fri, 23 Apr 2021 03:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=YJZaoWdkeQnUY9j6J7eTKZgTjYGHKGB6/6rEdFFQe98=; b=beqpNJ72OzZmv/fLA2ZCJ0G+pFLU09kepwTJi9zuvZV9ZZfR6NqBDeUdERxay9IpJi zkoMXRfzGU7/Hh9oDtQLf+gdrfHvoybEAVpjZdXuPvgl+94Lomf0Ca8unCBSlxxFa79Q FFmxK/3sKRFInYb4TH/aaZ9PPl2S+gWDgAlfFq18/7Ho3MxPfkeg5oU2vXMp7JUFteWE ICno5wkW5Apo4SJ4ICaICYwM0+pO05z6dVbJ6En6ddlSmqUP/OC1AqCBmxQNkQzryHl4 vsBMKv/DS26j3TmEvEDNFsO9HgB9aNj6R03WGritQpz4vtz6ruLqWC6znDQms2cFAYDf 4eiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=YJZaoWdkeQnUY9j6J7eTKZgTjYGHKGB6/6rEdFFQe98=; b=eGyChUjxU4ZtFtnsZvhCJqRxgZO45sbKfDuZMt8mpJH7qPsSZ/cplxiOo/lUX20uZl NyMfvRofxWQyjuAMX48EQ5Iud/rLiV9csNRcbGA0/e72v1Q+peOYweYiO9hQ/mn4bPq/ w+Rnz1OzOFnJHpagaRHJSqU7yKyG42QYqnzy67RU0S7OFA9V8eSHVSuaT/5ochcOTCJh s1ugkp3h6R1c1guqY3LUEbFpIX4OSuAyLhTCeljFSGKC1cthhkYYAUr7GXHJe4zJUOr1 v/aEjinKTAXkYT3dV9/UPsc44+Qi16Sdh1WDF2pdmnHjR57KiVihsJ58IjL4FdJ48LWm GKrA== X-Gm-Message-State: AOAM532O4H65eVZqa0dnBjr9Q6GOdUGSQk175Sw814HPSUROafXzvWlN nSMi7DcQ5YXn1kf/m4/F302ZkQ== X-Google-Smtp-Source: ABdhPJzIcrcI4iYy/9BQUawjsw2eG72nBMivEh8e9Qpb7Hx+7AlNV8Wp+OHqNTBLn+PgjLSjWrvKaQ== X-Received: by 2002:a2e:9c01:: with SMTP id s1mr2266581lji.402.1619173521574; Fri, 23 Apr 2021 03:25:21 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id a11sm515574ljn.76.2021.04.23.03.25.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Apr 2021 03:25:21 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 983F310257F; Fri, 23 Apr 2021 13:25:22 +0300 (+03) Date: Fri, 23 Apr 2021 13:25:22 +0300 From: "Kirill A. Shutemov" To: Yu-cheng Yu Cc: 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 , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang , "Kirill A . Shutemov" Subject: Re: [PATCH v25 19/30] mm: Update can_follow_write_pte() for shadow stack Message-ID: <20210423102522.5djgt2fb3unsidnw@box.shutemov.name> References: <20210415221419.31835-1-yu-cheng.yu@intel.com> <20210415221419.31835-20-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210415221419.31835-20-yu-cheng.yu@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 15, 2021 at 03:14:08PM -0700, Yu-cheng Yu wrote: > Can_follow_write_pte() ensures a read-only page is COWed by checking the > FOLL_COW flag, and uses pte_dirty() to validate the flag is still valid. > > Like a writable data page, a shadow stack page is writable, and becomes > read-only during copy-on-write, but it is always dirty. Thus, in the > can_follow_write_pte() check, it belongs to the writable page case and > should be excluded from the read-only page pte_dirty() check. Apply > the same changes to can_follow_write_pmd(). > > While at it, also split the long line into smaller ones. > > Signed-off-by: Yu-cheng Yu > Cc: Kees Cook > Cc: Kirill A. Shutemov > --- > v25: > - Split long line into smaller ones. > v24: > - Change arch_shadow_stack_mapping() to is_shadow_stack_mapping(). > > mm/gup.c | 16 ++++++++++++---- > mm/huge_memory.c | 16 ++++++++++++---- > 2 files changed, 24 insertions(+), 8 deletions(-) > > diff --git a/mm/gup.c b/mm/gup.c > index ef7d2da9f03f..f2813cf4d07b 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -356,10 +356,18 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address, > * FOLL_FORCE can write to even unwritable pte's, but only > * after we've gone through a COW cycle and they are dirty. > */ > -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, > + vm_flags_t vm_flags) > { It might be cleaner to pass down vma pointer and dereference it within the function: can_follow_write_pte(vma, pte, gup_flags). Otherwise looks good to me: Reviewed-by: Kirill A. Shutemov -- Kirill A. Shutemov