Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1107816ybz; Wed, 29 Apr 2020 15:12:26 -0700 (PDT) X-Google-Smtp-Source: APiQypLScpEChazWLRYXb/BkKvLG8KLqkLtAL6zZYnLN/j2VZWY7f+TIPdIUxpVC1Udww5sgpVcW X-Received: by 2002:a05:6402:b4e:: with SMTP id bx14mr123683edb.1.1588198346589; Wed, 29 Apr 2020 15:12:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588198346; cv=none; d=google.com; s=arc-20160816; b=YQouo0KQ25/rKlSg7UvVk7EKxxG+m38QS8GNkwglaurmv/uv4ksr5prU4/ZsUz7b9+ MolehJEvUqWBlLBMpA/PJ82t+wbBtSVj0f826YergFsaXtz1ek2/T5NdWohkF3wMJ9ja BlSmfE/eSegyYwkqEiYI5c7gNer0QDeYNsaDabvaT+FCmvWVpg330V8fOAHGaOa9DMd9 s/ywDRvXxzdWfpvmMBaxPWwZtoNUg/HG3UKV7obAtDGvlCbXufCrgELFBUkThIyY/TJB uaF5RxlC7LK6P9vLX06c1SWI0pJC6B+Q4vxkpiSNiIa8gv+b3XLB6BS8kUiA95+0z2sm yezQ== 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:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=01zA1R6Sz5bmSl/WP/HIGrEe9AR7Nxahx0LDkzMDnD4=; b=ArKuLJ59/wC8y7tRhkkN9TJF0Umres6zrz1h3UJmYNwmuGYm+GfrqzS2Hkiuer4BRC Ta2ijqOw6yQb7rpFxstgjvndFuWHTOEHevxPnY4pwksaaBKHdmiZuDEU71yf58KkcHhO y8HXoEfWOIMLj1HNwWg889ZsXn0JmwVpPiyRGhQlW2AAR08Fr6Zu+ebRMnvh8+nV7t2U HIr+ZVaUFhIsd+Dv/zSyXZaYXgOCopzG1TtzGSv2rsHOAbN0kF5AAY3E6i2HqrH0XAkz UIfK2yA8EBDg1DIKdWzltw7hiAB+q7feAPgXV7SvUf/C5tO3Ki7oqUYFtlhRK1/ZJej2 fwsg== 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 k26si5027569ejc.127.2020.04.29.15.12.03; Wed, 29 Apr 2020 15:12:26 -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 S1728298AbgD2WKD (ORCPT + 99 others); Wed, 29 Apr 2020 18:10:03 -0400 Received: from mga09.intel.com ([134.134.136.24]:61302 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727908AbgD2WIt (ORCPT ); Wed, 29 Apr 2020 18:08:49 -0400 IronPort-SDR: Np27QN8MoqKqMOYmTlb9BnTOhf4rIGrEnnLSoGsKbx2ER23ivVz83XL1Ihsvp3QBvePIpcCFpd T2zitiS1G1Yg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 15:08:48 -0700 IronPort-SDR: /HLkJFyWpydO2gYkk+D6sDQAtu3H3fzWvMs66BdkD2fUoQNnpCWhJRSLecfZRJOsPbmza/Uoj9 66hKka/VlBqw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,333,1583222400"; d="scan'208";a="276308902" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga002.jf.intel.com with ESMTP; 29 Apr 2020 15:08:47 -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 Cc: Yu-cheng Yu Subject: [PATCH v10 15/26] mm: Fixup places that call pte_mkwrite() directly Date: Wed, 29 Apr 2020 15:07:21 -0700 Message-Id: <20200429220732.31602-16-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200429220732.31602-1-yu-cheng.yu@intel.com> References: <20200429220732.31602-1-yu-cheng.yu@intel.com> 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 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 f703fe8c8346..b9002f644806 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3373,8 +3373,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) __SetPageUptodate(page); 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); vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, vmf->address, &vmf->ptl); @@ -4033,7 +4032,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 7160c1556f79..0fa59b1562c6 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2805,8 +2805,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 494192ca954b..02762af1057c 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