From patchwork Wed Aug 14 15:44:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13763657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 120CFC3DA4A for ; Wed, 14 Aug 2024 15:44:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DD7F6B0088; Wed, 14 Aug 2024 11:44:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 146346B008A; Wed, 14 Aug 2024 11:44:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3BAA6B0089; Wed, 14 Aug 2024 11:44:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A87C36B0088 for ; Wed, 14 Aug 2024 11:44:38 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E6B83A782C for ; Wed, 14 Aug 2024 15:44:37 +0000 (UTC) X-FDA: 82451273394.27.AAA8C9E Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf05.hostedemail.com (Postfix) with ESMTP id D4E25100023 for ; Wed, 14 Aug 2024 15:44:35 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="cx/fp8n6"; dmarc=none; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723650223; a=rsa-sha256; cv=none; b=eFqfPXXOiTLH95hyjjyoM6sKsYlahRjXTowgx3YCwaGbCEq4HsQ1HTFFJSJ+mLSTrwNFRT qVOGAHe2/t0p7Z8ngjSb75vZnQ9I2/EYmUegN5llkWH0IsbQgwr1UF4xZL+a0T2MuiEeZ1 kLZLUUCW2ozlu40NCseJojFLxgBmlRw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="cx/fp8n6"; dmarc=none; spf=none (imf05.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723650223; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZfJtp4EbP1iZkIk82oFzdjbw9nzCO7poA8zUpczfu6w=; b=odQVOWxfB3lPiw82afjY+fBlBxRP2qDm+yYvBuLaoRK38AEw50yM6bOOOZkxZB77gofFOk 3zIwBdCktccpIL+cEh981ktgdnYU010EKBOUIPuErPC7VAeoNEoa/CgPEmLNJCAHbv8bB5 AO7xdXIoWk+zQBYo/iXWJyOfkfjjT2o= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ZfJtp4EbP1iZkIk82oFzdjbw9nzCO7poA8zUpczfu6w=; b=cx/fp8n6YDoLDZDivZBEBUPoBf 7ObTXu6V8ldOrCsCH5JZwR6HapYacQsPn0OkQwh3rD/6MX+Z7ptLSqPxtGA1Ga9ROwWnR1pGnGe2Y Y6qIoYBD6p4j31Jmi38iLW6ye9WfdpNIuDoGkZtb/wxSPxL8w3nmWuNji790lX/oyS0K7mQGE92Nu lXbS4ZKPeV3GwTbi1i/jYpk1PMHy47lXAOQzZs0rPeUZnOJD1K2CVm1acSk1oBiPMZG/CoeU8DyzP Lq2/qMKI2u7/MdGoMqnYWaUiFBqT1wAM7IpT0SmLSX3naLwhT9HOeg9srCDiFcjf3FH5XKnMQdEWn O9oGjloQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1seGAs-00000000gHE-0SrN; Wed, 14 Aug 2024 15:44:34 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-arch@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-s390@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org Subject: [PATCH 2/5] x86: Remove custom definition of mk_pte() Date: Wed, 14 Aug 2024 16:44:22 +0100 Message-ID: <20240814154427.162475-3-willy@infradead.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240814154427.162475-1-willy@infradead.org> References: <20240814154427.162475-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: D4E25100023 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: enapsf5g6ju6b1h6ooey33qa8ors3e6u X-HE-Tag: 1723650275-421224 X-HE-Meta: U2FsdGVkX195ps8RI6yeXeEpgkuyeOTWYql4j7EjULe4CALGhyWvN9xGWUByskgh7j+y1UTCM0NO9yWLPcWdG2zmX1Tvjrgiz9LO13NbVZbE0LCX/7sDDy7peIR1cF8fp54HVQuwd7RyfZTS9fy1MWUYftD896+D2UDkN3y8xWhDOiW3B6mKTPOBbIf7yH4OPiF8da9G8si4aGXV1p7HW6j1Q7nuASGts7jl5p+vqVqKbhTbob/UtaDM8eBST1ViEwCOdld0bHZj8F+kpr1hp82eCbmtuU7wVowUx6gDU1+qbdqE3BV91tGgh5f17sTj0QshrPnhglYUoVbG12SC3KQhXCRZmzI98osA8wok0CAygr6m8bTBNX+0Uw37GrYc+tnZhv62tTleNf06O/tJXCbnPYqM8NbZxtSJFih8By7M40U/WN1ZnKFEm/Odp+hOpYJTyAtCXO9MpTITEKGU6VCtooi1eKgKDiS9ew9gDvuFZfk2o2ZgqcpCo/STtUyE3lgK/FDNXHqFAItXy0hl7zEhMXOBlM2aSe1HbAryckX7SS442zkgf0ud1ZnZSS5BIMA0j23dNsyiLwzugg4UmCqav9Vt7S8OkZauV2HBPvAMPIDkXo2rKxaP6EWOLdyDrLS/mv7JqXHaQRooAGMm0bPKaRkHSws72jLkUUVrnPhVgCkhfAayF5wlXYNu/3KGsWpYvxx3H9zH5s+GARmt+x7ukv8FrAQFyA6aNe95VgIPWJZH57J+bD5KADbxstokbdJX1kdPgGCX4GNkO/CE1uHvoaqMSZ/nqMhaMp4pwF+Whj2MTh1nEfnLCBSp1vf3z0whZCTe3MGEWLoDwbSSQLymBvZetj9JVjiUaBNZztFoktE3b8gNcwMLAyG5SnoSKapZ/y4S+0ODTRlG43o4vX8gPxpOLklWkJCBgG3YT/jTQyUwAaMGTG9gfxrwXlbpyqpBtwQgZSRO9R6lt60 1TSurZ0K C3iktKF3nVaHiRwYZGIMtdVH1NZ37cw3gMkEjausG/loXZPYmoC3nzD69Ks0u2myLf5mgLfv30Gl6aQpfYkr5A1Wv0IYEpQNIBjeWzYFuDtzQ65vKx78qIi1AuhdTiMPnBdmk31tuAEPQLa93KFQH5Me4P9VwbZJkahwHE/lwqADqCr3vXvnMAEAX3QjgQM5VDRuO5eb342jCCIGP1ztL5zDhFkYQW8hqklKp8X92JShxJxshxoY+0X3JwrG1bGwZFc+H X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Move the shadow stack check to pfn_pte() which lets us use the common definition of mk_pte(). Signed-off-by: Matthew Wilcox (Oracle) --- arch/x86/include/asm/pgtable.h | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index a7c1e9cfea41..59baf4e183b2 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -760,6 +760,9 @@ static inline pgprotval_t check_pgprot(pgprot_t pgprot) static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot) { phys_addr_t pfn = (phys_addr_t)page_nr << PAGE_SHIFT; + /* This bit combination is used to mark shadow stacks */ + WARN_ON_ONCE((pgprot_val(pgprot) & (_PAGE_DIRTY | _PAGE_RW)) == + _PAGE_DIRTY); pfn ^= protnone_mask(pgprot_val(pgprot)); pfn &= PTE_PFN_MASK; return __pte(pfn | check_pgprot(pgprot)); @@ -1056,22 +1059,6 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) */ #define pmd_page(pmd) pfn_to_page(pmd_pfn(pmd)) -/* - * Conversion functions: convert a page and protection to a page entry, - * and a page entry and page directory to the page they refer to. - * - * (Currently stuck as a macro because of indirect forward reference - * to linux/mm.h:page_to_nid()) - */ -#define mk_pte(page, pgprot) \ -({ \ - pgprot_t __pgprot = pgprot; \ - \ - WARN_ON_ONCE((pgprot_val(__pgprot) & (_PAGE_DIRTY | _PAGE_RW)) == \ - _PAGE_DIRTY); \ - pfn_pte(page_to_pfn(page), __pgprot); \ -}) - static inline int pmd_bad(pmd_t pmd) { return (pmd_flags(pmd) & ~(_PAGE_USER | _PAGE_ACCESSED)) !=