Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4068384pxu; Mon, 12 Oct 2020 08:41:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyX99yJaJgVYqUZw6J8rN/+h/yuKhE/2j3LuGCYIGQTESg5MpR2KqmCKJ34QZW1uyeDR96T X-Received: by 2002:a50:d654:: with SMTP id c20mr3672800edj.54.1602517318773; Mon, 12 Oct 2020 08:41:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602517318; cv=none; d=google.com; s=arc-20160816; b=KfYxbXIwT0wOC8Ky+igqKoZ2noEwcxQj5cHjBwjzcu2cUlB+0VXp7YgY8T2oEV8euy qsrusq1+DCIiCdTagGp7KPCm/LPGFkqy6gHL/jUgwVpVWPgaploJEWMgHL7Hd2PjBDSe Bw4Hp9/3id2iaYU2zXIFmaCTcJ5vUx+aZqvUi0e17oAFqJUF2ineO3asD5uPEnHDFRwQ VU19IgQAUNzh46nKHQRIEalaULK2ZNYuFEAkFBnZkZ458GVSn+xfaXNDartNRKj9nEJ3 XTQL609RDZqE97f1kGO+brsaH/Fh89gRfwu3Gy5ZeV7JGOekLWhZXf8ZAh0sJ9R97M0Q JugQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=m21XN3p3bMzj1PBAh1KsYCEHSoBfNZuIayyv0BATbss=; b=d/jK2tuzysqOs5aA0mcUBGww3qxyBC+9qTgHUd4XAcxIESVvBXKmkeXMjv31TmLOkC E/vzrmRLF7dSNayo5EaXISTdsV79fLMbRvzeegHhYvUG6OeNOM0taeBp8wD3t07bpsiL 37pDBiGt6nQOkOXDnklxTUJfkr5NY7fnulIm81xFRyZRTmPlTKyk+MnzEi6biT4fd8cp rRMVevBuqPf/kRAFU/7MYq5vKMKGgBd343ziVX7LmlqLo+UvB9d1iXSXrEf4Qhj7c+43 OUAWw2W3jUTGRjlqdPLWshqM6RqOJ6IAcdxwCiF2RS7exlwL7rfXzezFNTvMzDlQ6r6o v/BA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si8851176edr.209.2020.10.12.08.41.35; Mon, 12 Oct 2020 08:41:58 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390433AbgJLPkP (ORCPT + 99 others); Mon, 12 Oct 2020 11:40:15 -0400 Received: from mga05.intel.com ([192.55.52.43]:1318 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390327AbgJLPkH (ORCPT ); Mon, 12 Oct 2020 11:40:07 -0400 IronPort-SDR: Q3wXJIEPN83xoNRokZ5bnva3I0memAOEycgZBnSN1WFdNVsyzZ981hrrzmn60EdIiI1ZM26t1R u8QDblM2hEZw== X-IronPort-AV: E=McAfee;i="6000,8403,9772"; a="250452690" X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="250452690" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:54 -0700 IronPort-SDR: /wlQ6GJR1qm9swFA+c6fGrCz4jH7OZP5DR3w6ZddQCiqHhzAZ4P+/neaCjvM01kghUEO5Ic6Ak XMGbDl2jK2Zg== X-IronPort-AV: E=Sophos;i="5.77,367,1596524400"; d="scan'208";a="530010878" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2020 08:39:53 -0700 From: Yu-cheng Yu To: 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 Cc: Yu-cheng Yu Subject: [PATCH v14 15/26] mm: Fixup places that call pte_mkwrite() directly Date: Mon, 12 Oct 2020 08:38:39 -0700 Message-Id: <20201012153850.26996-16-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20201012153850.26996-1-yu-cheng.yu@intel.com> References: <20201012153850.26996-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A shadow stack page is made writable by pte_mkwrite_shstk(), which sets _PAGE_DIRTY_HW. There are a few places that call pte_mkwrite() directly and miss the maybe_mkwrite() fixup in the previous patch. Fix them with maybe_mkwrite(): - 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(). - In do_numa_page(), if the numa entry 'was-writable', then pte_mkwrite() is called directly. Fix it by doing maybe_mkwrite(). - In change_pte_range(), pte_mkwrite() is called directly. Replace it with maybe_mkwrite(). Signed-off-by: Yu-cheng Yu --- mm/memory.c | 5 ++--- mm/migrate.c | 3 +-- mm/mprotect.c | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index fcfc4ca36eba..5fde329791b8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3563,8 +3563,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) entry = mk_pte(page, vma->vm_page_prot); entry = pte_sw_mkyoung(entry); - if (vma->vm_flags & VM_WRITE) - entry = pte_mkwrite(pte_mkdirty(entry)); + entry = maybe_mkwrite(pte_mkdirty(entry), vma); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); @@ -4218,7 +4217,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) pte = pte_modify(old_pte, vma->vm_page_prot); pte = pte_mkyoung(pte); if (was_writable) - pte = pte_mkwrite(pte); + pte = maybe_mkwrite(pte, vma); ptep_modify_prot_commit(vma, vmf->address, vmf->pte, old_pte, pte); update_mmu_cache(vma, vmf->address, vmf->pte); diff --git a/mm/migrate.c b/mm/migrate.c index 04a98bb2f568..bba81bbcee80 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2904,8 +2904,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, } } else { entry = mk_pte(page, vma->vm_page_prot); - if (vma->vm_flags & VM_WRITE) - entry = pte_mkwrite(pte_mkdirty(entry)); + entry = maybe_mkwrite(pte_mkdirty(entry), vma); } ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); diff --git a/mm/mprotect.c b/mm/mprotect.c index ce8b8a5eacbb..a8edbcb3af99 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -135,7 +135,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, if (dirty_accountable && pte_dirty(ptent) && (pte_soft_dirty(ptent) || !(vma->vm_flags & VM_SOFTDIRTY))) { - ptent = pte_mkwrite(ptent); + ptent = maybe_mkwrite(ptent, vma); } ptep_modify_prot_commit(vma, addr, pte, oldpte, ptent); pages++; -- 2.21.0