From patchwork Wed Apr 2 18:16:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 14036352 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 8CBC4C36017 for ; Wed, 2 Apr 2025 18:17:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D9D7280004; Wed, 2 Apr 2025 14:17:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EEF4280006; Wed, 2 Apr 2025 14:17:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF3D4280004; Wed, 2 Apr 2025 14:17:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B09D9280006 for ; Wed, 2 Apr 2025 14:17:15 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9C344805AE for ; Wed, 2 Apr 2025 18:17:15 +0000 (UTC) X-FDA: 83289910830.05.4E63E08 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id F1E7F4000E for ; Wed, 2 Apr 2025 18:17:13 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=mVU4fMKY; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743617834; 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=lQt3ECF7HP7bKw8TGZlgthrOL2Fo1yD9YApfXehCXOA=; b=jkq1x65C9vFWKJnhJpIivYUn+qbw4H3Chc/TUk+CK6mVl/NcCVd2MAXyYFKcKrp7viAU8x CTF0wyO1XgXvrJrO52QmcjacczDh3FskIH5CMVch57fysUeOl/e8tdUcawlzaL74tmIdxm xYOVMhF+hMai26XtDeqo1+0o27cXLYg= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=mVU4fMKY; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743617834; a=rsa-sha256; cv=none; b=Q8z3SqNms2RTp4QMV8L044wcjEgquv77fLuaVIPrrfOpoPvZPBRbBg6Y0vEB52Q+NICAaG xzFAo7M08UjZoxWCH/RogtGV96nYlaoffPqbEWrm/rk61J2lSmvngCiqM82o9S2v4O6OCG r9RsmOJPjZizhnHupJfVFZR3l1Gw3gg= 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=lQt3ECF7HP7bKw8TGZlgthrOL2Fo1yD9YApfXehCXOA=; b=mVU4fMKYZo4fhGv5FW3wmjkyha 8dHahroqgFb7sZtNN2N+AHtl+dt2Ff+FfCd4lL+h/tMyoMn/FyLIkwpK2QAI+JxgljprXpxK8nHz9 SX0gs9Wny+MF7sDRAOxub0bkZea7+as8ouymgZxreUFJ4DiLQPM0KWS+7V4l9z609wCP5icxwhCcY 0NsLvQq3fRfXgvyeWPA4vT64X6UTn7Xuw32h98DvGzCHe2rRFE+IrmZZyGeDOhDiksLgQvMRTVaRm zVBBnin0afWIEBR5+q3BDEE+MC8QytkOMKTHUdxyomgJ2xH3rdz/VUZSDUfoeTNYhFx3z9MeUx7yu 1qHOeZYQ==; Received: from willy by casper.infradead.org with local (Exim 4.98.1 #2 (Red Hat Linux)) id 1u02eF-0000000A0ia-1FWC; Wed, 02 Apr 2025 18:17:11 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-arch@vger.kernel.org, Dave Hansen Subject: [PATCH v2 04/11] x86: Remove custom definition of mk_pte() Date: Wed, 2 Apr 2025 19:16:58 +0100 Message-ID: <20250402181709.2386022-5-willy@infradead.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250402181709.2386022-1-willy@infradead.org> References: <20250402181709.2386022-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: F1E7F4000E X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: z95j9waoybmfxormspifq48z3tzwcp6b X-HE-Tag: 1743617833-352280 X-HE-Meta: U2FsdGVkX19ZxlPjRP9ZrdMYihVmHElRcG2mt4cFmW0lwaJR4SEKubSMjVc6fzyS500xdIx63y/7m0VEQ/XHGdksW3sieq1hoe38dMewV3t37aPLNULjiIW2OX5z4p5LwEtp0RetZsZiyFKO4dFjA2vGay8nNjWdpwBrjVrnyzF4oFAqsoq6UzfBA8iBnp/cV4BMh2zlRgC0+WxxyuQZsPrM+Lz9kgH0RR9mIaHIg0K3tmGvhNJui4palX5cbdBsMu26iEKKLk1JrkdXbKIpmsyCFvZc18Z4hkuyXdA9+BROW3QEP2Azlk0BBch8mOIU6TnONM79oKVCYiAF1n8z68SEbLLhv//ofpYb8JdDXj6umqI+fc8Rv6gzCKM2pQMa46VKTJXkG5pc6Faxx8EVxAVMnkFI4S3An2DYwolJLGPm/5Jp45hEIySjIqhm0rDonTKIW4fSOvDcwRaXQSEfKlpIo30y2pDY7ivqukzdgxRiwU43rjXyMS/uHKIzRTF2UlDeY+KfMWPn4iiFxrHb5YaAoZqP3WPmM943WhXkBXsXPR1T6K/Lj9jSaJP9lbf29gid6I1I6xaGn/D0C687jStp14JUNPqdAMYnL0Od8JcaYRgAItoDhYZfpnrDhQDcL0NzPm1MOEOPleFVgNU2s4jTp48e1QysdZhgt78jUYuJk+jR9hJmdy/NZ/16r9CuUECC846pk23EQqZOk4FUSiuns5f8KzFpFQm/7SepcXhDxikoi5AK8afDyfzwMeTIPYzD8IZxaYK+hAqUK6/17kKnjfYENlSpIkR8zaQegRtVJF3yGcYCeE0KrmRGJCp5dX6ZzUbvbUfrQCV9xF0eaFxhBKZZFt3frAT8+h48EM9x4W2ba3wcFxhWPgz4yYtnoax8dlLp10INDJSP99eqpSJHxmGkaE4AIKqDl7fiTp+K04rNUK/jrgNaMsamXGqDp/kLJzS4g/ais/ADczL a6AhV2fk lhEsIDmjMHSsm8G0FNZ55SfSk1EWNb7VsSPGqC7VZzZ3X1xYvTb/VOoygcOAND9Mx9xFoY8KzWe8uRBaj+ShDOPhMsK1Hsq19q6z2R3aerOs6N7zI5scSLelpP7J1wak7UJeeQB+KEDZ1uudjvk/UaEq4FeAxqBWYJcpGDn1rlVWMI+YyqOQuiWRkSFIPMBu2eJm1N+P3DH8hkqas7wfVcBP+Ya7BFyobKwmt/14Ho4SLx14Cwhv0fUGP86ma6jqGIINEDPhs3JNP3JK9rNOXpOaae7i85TCRnf0PR3w7TDb/h9RxVg4ool+7cA== 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) Acked-by: Dave Hansen --- 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 7bd6bd6df4a1..2ce98b547a25 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -784,6 +784,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)); @@ -1080,22 +1083,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)) !=