Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2294235pxb; Wed, 9 Feb 2022 15:24:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzhd1FGUrRH/0fHdYO8srzxoO1LWMh1RYtYMfuLvoRKSH1oZspfm0Hyohm+RiiP+NIarZRa X-Received: by 2002:a62:1ace:: with SMTP id a197mr4699791pfa.63.1644449056818; Wed, 09 Feb 2022 15:24:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644449056; cv=none; d=google.com; s=arc-20160816; b=FQx36PPD1xqgUmbNolsOxlxKQ9A3GoqLswvdDhiv3YDY/VYDpKo+X6qkwBv9nqVzeS RgKxx+YZo7AgIVlwS1Q1+Z7sidOph4EmTw73Hnby4CVhtCSIrcAZPfKSSCWWZ+5wbmUa r8DC0PUYctfAMiTispchlvqTP5H2yp1EJ56wkY40P0I7qvbfo66v4KfXlZh4164rStFH l9JAZvMJBVjRHE5AYTNvfNGel+l0KeD16/aGFPxR9EAm06eh/rSNsSQE+WCfLSvIkZ7T Qj4D7+6Rslp7r5d35GW3gf7WtP/crZresikHzXHwlmIenF7TuYKt8EY+7cJVONUJf99R L56A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=6xkhnP2xbDpxoXzYPGs2Z+s3F1rBBxfk8jLGSHZjpPs=; b=LAP9bmBk6U1j84m8x5wo+gNioy6QJLcTwrq4JC12hORCZJGt1MnxkZBp5/k52Vil4I Zs/h6jBXP5PYfs3W9oslgWActLLgNRAxxuu5NFYIpKA8q/1znlGc/Ho2oxSJKeuINu2H NQKb3Gt6lvW6WXy/WTATMBVn48ZLnDKAacmH2m+2bjKR5BQUz6kUDUfp+L9qkucb91Eq GoUhKEbHGA2v8s2Q+jI5EaeNN53tVtLgC/w6HK4/0TF7A79HP3iD4vtlCPNSzL13nX35 yN+T61l+64D9ix5/61ffpUZ+AbHpeMSySo1lyG8gTgaobKGEdoQNHkuoib0RCUVXWfCw h5LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d3EnY428; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l15si333117pls.278.2022.02.09.15.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:24:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=d3EnY428; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 14D7DE065090; Wed, 9 Feb 2022 15:19:21 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233948AbiBIVvu (ORCPT + 99 others); Wed, 9 Feb 2022 16:51:50 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:40544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233931AbiBIVvp (ORCPT ); Wed, 9 Feb 2022 16:51:45 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AB78C0F8692; Wed, 9 Feb 2022 13:51:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644443508; x=1675979508; h=message-id:date:mime-version:to:cc:references:from: subject:in-reply-to:content-transfer-encoding; bh=2XmQo/8+05nnCFD6IB5G6G1lj5TYd6uWzLLIRuhEalQ=; b=d3EnY428EmiNpKkzFpWC/JPWIifX/DdHy8jhx/tEoF3iXtjaunIrcqRO ztzv+e+73vzSjXeFeNKd1HKhVF1MfVZds8Rw142+1VswqjtkNkUZYVTRL yuHA4SMcuGtYVw7MwU8zUQS5LY8bJKY7Fv6zJX0tNkKEMFku1sc+8ozIN nEkfD+zlgNCwinFV6TLNDlVDmyggCCtgXOk6ML9Ax26hK0PPifb5uqYto SHQ3hTRdXba/3b8Jta0kyYGwPmMffNO62Jb9mCf5G9rRpoZjnTgy2dP8U e7oci8g0kla64QBE7xmfUjjqfJbuqEB4Br7xMDZpoQwPZLxaJ/H2o+SHK Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10253"; a="249102647" X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="249102647" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 13:51:48 -0800 X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="585733999" Received: from sanvery-mobl.amr.corp.intel.com (HELO [10.212.232.139]) ([10.212.232.139]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 13:51:45 -0800 Message-ID: <8065c333-0911-04a2-f91e-7c2e0cc7ec51@intel.com> Date: Wed, 9 Feb 2022 13:51:42 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: Rick Edgecombe , 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" , Dave Martin , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com Cc: Yu-cheng Yu References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> <20220130211838.8382-18-rick.p.edgecombe@intel.com> From: Dave Hansen Subject: Re: [PATCH 17/35] mm: Fixup places that call pte_mkwrite() directly In-Reply-To: <20220130211838.8382-18-rick.p.edgecombe@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/30/22 13:18, Rick Edgecombe wrote: > - do_anonymous_page() and migrate_vma_insert_page() check VM_WRITE directly > and call pte_mkwrite(), which is the same as maybe_mkwrite(). Change > them to maybe_mkwrite(). Those look OK. > - In do_numa_page(), if the numa entry was writable, then pte_mkwrite() > is called directly. Fix it by doing maybe_mkwrite(). Make the same > changes to do_huge_pmd_numa_page(). This is another "what", not "why" changelog. This change puzzles me. *Why* is this needed? It sounds like pte_mkwrite() doesn't work for shadow stack PTEs. Let's say that explicitly. I also this this is ab/misuse of maybe_mkwrite(). The shadow stack VMA *REQUIRES* PTEs with Dirty=1. There's no *maybe* about it. The rest of this is essentially a hack to get VM_SHADOW_STACK-required bits into the PTE. We have a place where we store those VMA-required bits: vma->vm_page_prot. Look at how we store the pkey bits in there for instance. Let's say we set _PAGE_DIRTY in vma->vm_page_prot. We'd come into do_anonymous_page() for instance and do this: > entry = mk_pte(page, vma->vm_page_prot); <--- PTE is Write=0,Dirty=1 Yay! > entry = pte_sw_mkyoung(entry); > if (vma->vm_flags & VM_WRITE) <--- False, skip the pte_mkwrite() > entry = pte_mkwrite(pte_mkdirty(entry)); In other words, it "just works" because shadow stack VMAs don't have VM_WRITE set. I think the other VM_WRITE checks would be fine too, although I'm unsure about the change_page_attr() one.