From patchwork Fri Jun 21 14:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13707658 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 27258C27C4F for ; Fri, 21 Jun 2024 14:25:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BA9B6B00FD; Fri, 21 Jun 2024 10:25:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 273FD6B0103; Fri, 21 Jun 2024 10:25:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F15346B00FD; Fri, 21 Jun 2024 10:25:26 -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 CFA676B00FA for ; Fri, 21 Jun 2024 10:25:26 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4CD90120BF4 for ; Fri, 21 Jun 2024 14:25:26 +0000 (UTC) X-FDA: 82255118652.21.78C00C0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 45D51A001B for ; Fri, 21 Jun 2024 14:25:24 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Q/PWYrIF"; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718979919; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tqSfUWMuuFFpoXlX71uD6ModhPCWC1FSZp1xmlIx7N4=; b=mxoLWAO3uYuMWiUNmqNzb/HKbhZr6U/1s40f68LCTcc5kMx9ICoW1NzmVHhdRd73Htpq8a irm3zSvTuYsMQo4myhQoJ699SdRfBGKLpe4GHamUBxbQTxn3zA3YXL0/fP91p6MAHRv5eb HYObF15D2Ogn4buA+PG4z2cYlisIo/U= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Q/PWYrIF"; spf=pass (imf15.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718979919; a=rsa-sha256; cv=none; b=yoRZG+EgBo6QwYRAWT27y3KeCEfJdmTp+sXrhtrMRlAshgpVGNCz6CIghBow5mo0jR7LGJ iv7ykvGq2A4AAG3VxUjVBMITHwjaK9UqNobePRgW85nGrZBd+rAvXtrXgKtJpsIZT2oh88 lvYIFogsHfBLuJjN8DBm9oNu+QSjSCE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718979923; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tqSfUWMuuFFpoXlX71uD6ModhPCWC1FSZp1xmlIx7N4=; b=Q/PWYrIFwYsOQkwMj1/MqEliOkiM84OOsJxRrWn8JcYYjP6HFD9bKJpbwBuLblvT+rsfn8 W3FJHqXZVnWfyWUE6zv3izzW+OWDo7yv7y9sqSsGWFxJ5kdqCrvCvWY1azTf0qJ2fgWC48 e1NetC2eUOWygigfS2alSkX1q24D8AU= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-CHQTQU0KOPuZOfxdZ_517Q-1; Fri, 21 Jun 2024 10:25:21 -0400 X-MC-Unique: CHQTQU0KOPuZOfxdZ_517Q-1 Received: by mail-ot1-f70.google.com with SMTP id 46e09a7af769-6f908f002c2so339989a34.1 for ; Fri, 21 Jun 2024 07:25:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718979920; x=1719584720; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tqSfUWMuuFFpoXlX71uD6ModhPCWC1FSZp1xmlIx7N4=; b=ZYzw87uGVrqfea5wnzoMjIvPFYe7JMQzAVq8qReXUW6HIOd6fxmsPtiP8LUo2qVNpX P5KULsGECLiL3Cmc5qCuGTdc8TdmyIOwtwp7dj6wBJLCRvVfHSeDvkSmKp6M2wtC59yd GIrzRBHziZolsO9b4z35lPLIIF7q7t61Xdza7r/N6ibd7nd/P1F3R1ZmFOiyLXhnQwCg wgKi/fVzM9zvQ62dHW/xC2ItPo3xnUmDZOSdyDm4WoDSgRlcDevV6lBeOcEkb0SQqMfk R4sjBrM+Nr5d0Wn7m6KMnMpyCxz4YKHkxOIUddBWZyueh5l1sGWRnMzwN7/N+Iu/fRNU VYxQ== X-Forwarded-Encrypted: i=1; AJvYcCXjso0qo9yWbminJcphEH9wiTMn5xSOqL/Q6z8a21RK0b+CyAeJPOCxwhiUsy6AeR0xpKGR8+Qj9uBfzlVVIwvG2g4= X-Gm-Message-State: AOJu0YwlLjyyyDxg9Oh3KAm77uJkAeHB2PQMoc/LT5438JDflQV3rNj5 3h8xzoOK+8XYWgBdoxZA88BIcHd/PVx5i1aKqhCtiQbOVxTancwDo4xYhfiNiPyGPFSWg8KayTC OZh7QnZw7xx4PMoJB7k/BXq95s8KoA9RHvqh9vcp5GTlnp2tm X-Received: by 2002:a05:6358:8096:b0:19f:81fb:131c with SMTP id e5c5f4694b2df-1a1fd1d513bmr911568055d.0.1718979920234; Fri, 21 Jun 2024 07:25:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOaIBFrX4PIBPbd7NrgasVtJd+jvRQiQvrolpQX5hE+bY+MZMCcoynbRsNLrRaLePwagbsiQ== X-Received: by 2002:a05:6358:8096:b0:19f:81fb:131c with SMTP id e5c5f4694b2df-1a1fd1d513bmr911563455d.0.1718979919599; Fri, 21 Jun 2024 07:25:19 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id af79cd13be357-79bce944cb2sm90564785a.125.2024.06.21.07.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 07:25:18 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: x86@kernel.org, Borislav Petkov , Dave Jiang , "Kirill A . Shutemov" , Ingo Molnar , Oscar Salvador , peterx@redhat.com, Matthew Wilcox , Vlastimil Babka , Dan Williams , Andrew Morton , Hugh Dickins , Michael Ellerman , Dave Hansen , Thomas Gleixner , linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Rik van Riel , Mel Gorman , "Aneesh Kumar K . V" , Nicholas Piggin , Huang Ying Subject: [PATCH 6/7] mm/x86: Add missing pud helpers Date: Fri, 21 Jun 2024 10:25:03 -0400 Message-ID: <20240621142504.1940209-7-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240621142504.1940209-1-peterx@redhat.com> References: <20240621142504.1940209-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 45D51A001B X-Stat-Signature: iny73pfp7p4ptix8jhmg8w7zza9hie76 X-HE-Tag: 1718979924-145272 X-HE-Meta: U2FsdGVkX180cvweJCHfdlvygvwtPmWAjyL22miZAihVp8VFCA2JQqne3Bzf7yjAUr102bogQOdZRK2YbeNd0VotRoBkgaSEGjY/xbcAewKBo9kp3Gw0qhFQe7hBgNr1FCSkPvCZK03oXVl29fI6LsS1zHt/swK4iJ9DRpnVekkMogon4um0hH2wJxl2J31DQtY0mCvMGwJXhU4UXREOCzSvBDxDelo8KAUkS/EduTFtmIzAVLPRahJ1zbRK7nw4id+rqK4wdWz/S0T/teGD/BYuf5Yw2pRVUtbKofTR6g6La3Y9j2FWmcCX4V376Apo8sM/zy1kHFkh4KvZueb8ZpcCFn1L4gJETIThGk3t+hCp8rYMIwrqAtPrcd4ejPakng3H7ILbwXkDh5am4MZnG2UXB6M3U1CelSVN26qVu1bcfSxKNf4osvU5pSzUSkYbt/CNQGgWf4KTzIGeY2AqEMnmKvubSJKcPEYftna3ljoxq2zybEiG57T0o2htZDTK8Vfhj2kA4zTzIkk00WBySUOW6i2ul7Aq/mBpbts/CBMkJdywZQeT+sssjSnQ3/sff0NCoq/gHtc332Bq8506oyuOaFKdsybOZ3xSdL4fccSd/edVa3aMuOeB7ko9mNrFfXzpjTXhWOvkNvoUraJntCVNTtt4P8Quqpq/cFhkcxVYNwge1ILk1nOCGsAo/AWUgBM/eVYtM/99ARotEQjxlNCe4gNgo88gpt+ipQB2qYtAMY8CHnGs6IJ+aCjrp8nok9f8FikAXtkfPZWlZUct+R5SU5newP4xuyVk+N294L8y4ur4242UIsrPC1R97Dz+Qc2FH/D+UAOK7NBA/2hTWGtTVc6JF5P2d+Xm8tnX/GnZXZzk6ppkx0i1VK3e0EcE1peK/GBf1ZR1eFZ1Wz7z+/wxRNnIaq7PaA7Rhq6kF/H1MWqY6k2FqB5Gat6nGgnfOQix2TOaE8WtcWSvkLk 1+51cM+F zwSlqMQshO5Dgt4lnixJKHQAy6BMbXfZJwY47g3Gxk6oHX/wHGGoSogtDPDcGssfaoFcoydKx2lGdXZv3+4KTxTIGn4NfMTsJ7fOGZjmcsL97OY2H0G+ZuEhrO+OLDsRoaW84OrXB4u0pQS6S0Wn7xeqnom3VNF6/gT+zLXmR1DvHUoSO+d/g16kFGUkgnM2FJQ0Hag0RIHEIUfUBZqPz+MN1VRFaJ9yaKP0RD3ilaRIY+Bxpy1z6ZTy9cf9zJKCMDK+c+4ayoA+ybCK7yok6Rg4UvfTL7pYVeHexdGtk1N2jGk8Ug5EHpr4K7wlIJ/inqL++w28X2k/MvqApregI8DIhu2+XJFLYWyTT3eMmQByv23j+FpIfvCWAaumB+MXjbpwMxgHJZI+irLc6jOCXtNL80EFAXBRipOYl6VvnDwYB2Fo/eo5YKwRnU5CcoW9zLkokiotx2AU0Kj2jsMMJi3UiaB8spikuxBF3TsdXFe01sO2pMsP1gl6N2rcgQYNBOO7b 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: These new helpers will be needed for pud entry updates soon. Namely: - pudp_invalidate() - pud_modify() Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Signed-off-by: Peter Xu --- arch/x86/include/asm/pgtable.h | 36 ++++++++++++++++++++++++++++++++++ arch/x86/mm/pgtable.c | 11 +++++++++++ 2 files changed, 47 insertions(+) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 25fc6d809572..3c23077adca6 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -775,6 +775,12 @@ static inline pmd_t pmd_mkinvalid(pmd_t pmd) __pgprot(pmd_flags(pmd) & ~(_PAGE_PRESENT|_PAGE_PROTNONE))); } +static inline pud_t pud_mkinvalid(pud_t pud) +{ + return pfn_pud(pud_pfn(pud), + __pgprot(pud_flags(pud) & ~(_PAGE_PRESENT|_PAGE_PROTNONE))); +} + static inline u64 flip_protnone_guard(u64 oldval, u64 val, u64 mask); static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) @@ -839,6 +845,21 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) return pmd_result; } +static inline pud_t pud_modify(pud_t pud, pgprot_t newprot) +{ + pudval_t val = pud_val(pud), oldval = val; + + /* + * NOTE: no need to consider shadow stack complexities because it + * doesn't support 1G mappings. + */ + val &= _HPAGE_CHG_MASK; + val |= check_pgprot(newprot) & ~_HPAGE_CHG_MASK; + val = flip_protnone_guard(oldval, val, PHYSICAL_PUD_PAGE_MASK); + + return __pud(val); +} + /* * mprotect needs to preserve PAT and encryption bits when updating * vm_page_prot @@ -1377,10 +1398,25 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, } #endif +static inline pud_t pudp_establish(struct vm_area_struct *vma, + unsigned long address, pud_t *pudp, pud_t pud) +{ + if (IS_ENABLED(CONFIG_SMP)) { + return xchg(pudp, pud); + } else { + pud_t old = *pudp; + WRITE_ONCE(*pudp, pud); + return old; + } +} + #define __HAVE_ARCH_PMDP_INVALIDATE_AD extern pmd_t pmdp_invalidate_ad(struct vm_area_struct *vma, unsigned long address, pmd_t *pmdp); +pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address, + pud_t *pudp); + /* * Page table pages are page-aligned. The lower half of the top * level is used for userspace and the top half for the kernel. diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 93e54ba91fbf..4e245a1526ad 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -641,6 +641,17 @@ pmd_t pmdp_invalidate_ad(struct vm_area_struct *vma, unsigned long address, } #endif +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +pud_t pudp_invalidate(struct vm_area_struct *vma, unsigned long address, + pud_t *pudp) +{ + VM_WARN_ON_ONCE(!pud_present(*pudp)); + pud_t old = pudp_establish(vma, address, pudp, pud_mkinvalid(*pudp)); + flush_pud_tlb_range(vma, address, address + HPAGE_PUD_SIZE); + return old; +} +#endif + /** * reserve_top_address - reserves a hole in the top of kernel address space * @reserve - size of hole to reserve