From patchwork Thu May 23 22:37:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13672345 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 2F5FCC25B7C for ; Thu, 23 May 2024 22:37:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 98AA66B0092; Thu, 23 May 2024 18:37:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93A526B0095; Thu, 23 May 2024 18:37:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B6256B0096; Thu, 23 May 2024 18:37:56 -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 588C76B0092 for ; Thu, 23 May 2024 18:37:56 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0909C140435 for ; Thu, 23 May 2024 22:37:56 +0000 (UTC) X-FDA: 82151124552.16.A5632C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id E2A3540013 for ; Thu, 23 May 2024 22:37:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GKtorzF1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716503874; 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=C5pESLIFkXbJ9rNrzrPx/8xy3yB6kYubSyOytZTtev4=; b=i+RU6rvxaxkAgkpoCWb/X3mACgPkM/Q9zViq41N289ZaDiq9QDwy1TuNlQQumEF7uODW/0 BoYCe+VNPzbtVETNRHo5AYyeMiX9e6VV3Ki7VPWQMQHRj8Y8hMgDIRf8C9QoMi2y2LzcBW eXMIfMcfX6oEu1s9LXvQNe36AWbAPTQ= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GKtorzF1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf01.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716503874; a=rsa-sha256; cv=none; b=nolOMWJZS19NOuPrsCHBBRVkESc/MOjkbt5e0hlKrKtsi3op0DJkY0bBXH4YdALtsCTWTW HvdoAsdRdw/BSNIpUjQ1opaP2UulK4Dnc0Yz4YOJl7H4QPa5dVCp+YYPpN054XX6Ao1ovM RQ15qQsSHagHhivuN0/oud/Gkl/+3T4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716503873; 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=C5pESLIFkXbJ9rNrzrPx/8xy3yB6kYubSyOytZTtev4=; b=GKtorzF10lKqjLGAJ6ulT0hcT7DL/aBelh39OE4vQb7q9tI89CDj+LV6SdwOyvYAaZpgvg bJZJVB8bABiHnrVnPUBSqBhHZYHbruL0RN1pBzsVyO27uI/5AJqJaw6t5FZYPFDmgfAI1+ o4TIjXYX+0yvN3y0aN7/KKn+ypnrY/o= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-225-K-LTcUGLMyuyNVOmxLFPiA-1; Thu, 23 May 2024 18:37:52 -0400 X-MC-Unique: K-LTcUGLMyuyNVOmxLFPiA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6a35d03abb4so1402616d6.0 for ; Thu, 23 May 2024 15:37:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716503871; x=1717108671; 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=C5pESLIFkXbJ9rNrzrPx/8xy3yB6kYubSyOytZTtev4=; b=GdpwuJ0HMTdxzvAAf/1m0f+7mS0lf0CFHPmoyErBy751YHW5cGDx1Y2UUE7gbw28k4 WMTU93AB6cKSTAGYTCCv2IUTRWIFXMDoXg0JAWQTyb7yAbUbAI3U11JKUfXVxe6KGoL8 +Q7qVgdiXfXCbF9+/rKh3BsVbQqX/KZLAGtpNOFIgYGbTAX9v9d5XXwZ738Cv73Lhg68 SSF8Ko08Mg1wf88BP6VFXZnW4A28/9wZHcMUB+kYqZTcJudR6wUJQ0oKg1rAD5dPt6cL n6dhYSdyn5qXsasmsjYUTlJBhON2vocLIU551gYPzmEN4KZPXXqqID8TFVk9bD9WlVIn rLVA== X-Gm-Message-State: AOJu0Yzk35JTwVboyNsMZb6swnPKyLgXy1tjYOCejkX83LcC3gcprg5w wWdcyRQthQAMMzEJvoAA1KGZBRt1HaDW1E/BR8J9pRbz8OAxyZsu105rWhkxpwtKF6kmYViXKw0 W1pip2bSLs6S/OCKBKLGfmXOXOX6kR8G3/8WF/0IOhxqGMkydChrBl5ly+MEuQi4vvubTdcLtTl n7wDTepxxGYBq4Ckb50/ktqUJeYzXn2A== X-Received: by 2002:ac8:590c:0:b0:439:a36f:eaeb with SMTP id d75a77b69052e-43fb0d79eefmr5060811cf.0.1716503870831; Thu, 23 May 2024 15:37:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBsa85pBg63N2c/DHFGiqK33waIm3Jb+f2auHqGTdFvIXtAgZRarZeur5jH8bVIPCG4ZRiKQ== X-Received: by 2002:ac8:590c:0:b0:439:a36f:eaeb with SMTP id d75a77b69052e-43fb0d79eefmr5060331cf.0.1716503869770; Thu, 23 May 2024 15:37:49 -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 d75a77b69052e-43fb18af1d2sm1066701cf.65.2024.05.23.15.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 15:37:49 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Jason Gunthorpe , Andrew Morton , Al Viro , Dave Hansen , Andy Lutomirski , Matthew Wilcox , peterx@redhat.com, Dan Williams , "Kirill A . Shutemov" , Mike Rapoport , Ingo Molnar , Michal Hocko , Alex Williamson , Peter Zijlstra , Suren Baghdasaryan , Borislav Petkov , x86@kernel.org Subject: [PATCH RFC 1/2] mm/x86/pat: Only untrack the pfn range if unmap region Date: Thu, 23 May 2024 18:37:44 -0400 Message-ID: <20240523223745.395337-2-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240523223745.395337-1-peterx@redhat.com> References: <20240523223745.395337-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: E2A3540013 X-Stat-Signature: cnrmc9f5bct5nbqr6ywfks8fqyy5bx8w X-Rspam-User: X-Rspamd-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Ff+W+McY7S/0MZRGaZjmKNSvh5C8Ej87Vpvk3Pbk9P/9sSKmd0DrAe3RsLfm20pBg649IpnrF/+3gtqeiwnTDapWt9c2UpPd/jEwsorzQ1Xu854XjY/Gw6pmE2uF5rb7EkN2zYCytwbxQyuS5wGJla5QxrvwiYyePalIFPWf7YHGo+4+evtoAOmYt3f60O8G9bzex8eZ6gP6ab26h5hkiJispbtvv0TYHbtJae/Ch6HSjy5UBmmi7caW0b64EcB199Tj0C4HdIYGFTSACBS5h69ahW7KmM032Tn39lI+Dyiu6OW9CzI3Oz7DYCZ2XpX9BilyIr6Qyfc+yiza5HNdkIMp3gtroHjJtsYklzCGiy6H3M3XZTO5P58uHnY1XBG+SDIuGEWZQ64ljIxi2YiBdNbUPyQvhLOHybsbur3E+D8kRflFYOCrVgdyE1WMsmwQ0QCS8MHXNw6DwPHX0Q6wB+uztuk7dt5MkhMcZYra9aYV7KQXZv7LnWTnvaJM3+YNeBGUb+Y5s6WiBOYra+oWPm3judbBS2ogYqtPo8fr2eyszzjkaZjfgUXNCq09wc2/iI62abM1OoZWrVwX4yTHNNnp2xD1qQ== 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: X86 uses pfn tracking to do pfnmaps. It looks like the tracking is normally started at mmap() of device drivers, then untracked when munmap(). However in the current code the untrack is done in unmap_single_vma(). This might be problematic. For example, unmap_single_vma() can be used nowadays even for zapping a single page rather than the whole vmas. It's very confusing to do whole vma untracking in this function even if a caller would like to zap one page. That may not yet be a problem, may because of multiple reasons: (1) Things like MADV_DONTNEED won't ever work for pfnmaps and it'll fail already before reaching here. (2) If some pfn tracking is lost by accident, the default fallback is to use UC-, which might be safe enough even if it may not be wanted. One can see track_pfn_insert() -> lookup_memtype() which can fall back to the default _PAGE_CACHE_MODE_UC_MINUS for a MMIO range. However there's ongoing work [1] on VFIO driver to allow tearing down MMIO pgtables before an munmap(), in which case we may not want to untrack the pfns if we're only tearing down the pgtables. IOW, we may want to keep the pfn tracking information as those pfn mappings can be restored later with the same vma object. In VFIO's use case it can be remapped later if the VFIO mapped MMIO region got re-enabled (e.g. PCI_COMMAND_MEMORY set). In this case we should do pfn track for the whole lifecycle of the vma. IIUC, this was overlooked when zap_page_range_single() was introduced, while in the past it was only used in the munmap() path which wants to always unmap the region completely. E.g., commit f5cc4eef9987 ("VM: make zap_page_range() callers that act on a single VMA use separate helper") is the initial commit that introduced unmap_single_vma(), in which the chunk of untrack_pfn() was moved over from unmap_vmas(). Recover that behavior to untrack pfnmap only when unmap regions. [1] https://lore.kernel.org/r/20240523195629.218043-1-alex.williamson@redhat.com Cc: Alex Williamson Cc: Jason Gunthorpe Cc: Al Viro Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Kirill A. Shutemov Cc: x86@kernel.org Signed-off-by: Peter Xu --- mm/memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index b5453b86ec4b..9db5e8730d12 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1821,9 +1821,6 @@ static void unmap_single_vma(struct mmu_gather *tlb, if (vma->vm_file) uprobe_munmap(vma, start, end); - if (unlikely(vma->vm_flags & VM_PFNMAP)) - untrack_pfn(vma, 0, 0, mm_wr_locked); - if (start != end) { if (unlikely(is_vm_hugetlb_page(vma))) { /* @@ -1888,6 +1885,8 @@ void unmap_vmas(struct mmu_gather *tlb, struct ma_state *mas, unsigned long start = start_addr; unsigned long end = end_addr; hugetlb_zap_begin(vma, &start, &end); + if (unlikely(vma->vm_flags & VM_PFNMAP)) + untrack_pfn(vma, 0, 0, mm_wr_locked); unmap_single_vma(tlb, vma, start, end, &details, mm_wr_locked); hugetlb_zap_end(vma, &details); From patchwork Thu May 23 22:37:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13672346 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 9A61AC25B75 for ; Thu, 23 May 2024 22:38:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F9EE6B0099; Thu, 23 May 2024 18:38:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B72D6B0096; Thu, 23 May 2024 18:38:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B1D66B0099; Thu, 23 May 2024 18:37:59 -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 D8FE66B0095 for ; Thu, 23 May 2024 18:37:59 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 5474C1C113B for ; Thu, 23 May 2024 22:37:59 +0000 (UTC) X-FDA: 82151124678.17.9203BF5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 55B0F40020 for ; Thu, 23 May 2024 22:37:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D6JxcPEZ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716503877; 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=U8kmpLF+0wb5DY59Z4GvPb8KdcMgneGoHIufiMB6jJ8=; b=ZydSTKn3dO+TAujF/WeP5hY5bRxSmmDRUNRyzfNDW9niY/ewQ+EvmppFeRrv40MPqLtKQG RtzGS137gq1EhuoQclgIoazrs0744ak5mIrgm3LdjpSruD44gzFQONr6hrrFEsySfLmB0d 6EBJHrz9ut2Ul48nw3z+P6sRkxxkDdg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=D6JxcPEZ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716503877; a=rsa-sha256; cv=none; b=VMKRRvnWNuOCQViiCptPFAjkY/GeAgU3KKaav+bfoYd6FyxnV+Fi41D7OgTduY+iMgChi6 f7mW0WTraJ4SlxMAOrrZed9wGdPN5a3QPEmJa4HVzsjEqj1uVC6v8EnYS0OUlc5K4b2SN5 PN8XlxWM4L3GeW+HzKcfvHSwiE1ZrQU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716503876; 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=U8kmpLF+0wb5DY59Z4GvPb8KdcMgneGoHIufiMB6jJ8=; b=D6JxcPEZ1lnJcYhoDLJGCD2w4F+v0CYaaSaRY+utlB2Cg+pYSpUV+EigMqzsWUfZPwjRuP mNwAnYEPfDnwMkFHuSC+WBrmFklKz/j0RuvjJUl0RJiH32t1akfcdf9B0HL9KdIMZmp8TT kppa323OOmhxVi2/5gbv01bQAKz29PI= Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-IglmQGcAM1CLayeeJ5GukA-1; Thu, 23 May 2024 18:37:53 -0400 X-MC-Unique: IglmQGcAM1CLayeeJ5GukA-1 Received: by mail-oo1-f72.google.com with SMTP id 006d021491bc7-5b96a8bb2faso56446eaf.2 for ; Thu, 23 May 2024 15:37:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716503872; x=1717108672; 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=U8kmpLF+0wb5DY59Z4GvPb8KdcMgneGoHIufiMB6jJ8=; b=b4KS6w/1uOCOGTV0EIkufEa/NYTGBRhxP4q/P6vPvrJqdEEYTG0K/KVfr5PVw4iTM4 aLpT2hxtNHewCgyrOZvgghSSKnkSyJ0nBGY03x1ba9wvunZs9qxXfS12t6C+yOFPUPzE mL3g8AVYCLLA+g5em2uM8/z6AZwfj5oyYKcKoAQyaeT4ZP+PtVQuXdnrA5W2SzClGpz6 3k7pWIU9TqAlaolt4SXBk78l/RAe51D92xUZXGLUeEpVl7NSckqTlFlTI8Hi7G9saB0t ZjSNn1/PQiy9BIIsSXXC8A6QmO8ghI/BMiD+ai31m11jbCyMc06Vl+ub6L8FbanUnrP1 uOOg== X-Gm-Message-State: AOJu0Yyz0Y60RwOGan6Ws9TWV3Dd2OaKni3R/HEidgj737yywo5uH4Og N+tgZLKUTvNj63sCDv5sjv+U+RUMbS7ZCDwz8e9yyrMWCQ100+ywv4PWQllhipBfUq3ohpvAHiD AqryHow5gky6CJtd04F1IX5JEvMoo2rs1ZqjuoXnEBKTwilK8Y2Z1Sh+bgTZ96Ymf/xPsUuENon ywz3MlF6+3lNLC4z21OhSmyChY88WcYQ== X-Received: by 2002:a05:6870:f708:b0:24c:67b8:2cb8 with SMTP id 586e51a60fabf-24ca0d87c0amr711193fac.0.1716503872081; Thu, 23 May 2024 15:37:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHv6EB8iQs0dh9WTeZd8gUJptLRKFfW4krudfOlO5TrsX7uonwQfj9xz3QTacSLo6+IAfGxJA== X-Received: by 2002:a05:6870:f708:b0:24c:67b8:2cb8 with SMTP id 586e51a60fabf-24ca0d87c0amr711127fac.0.1716503871277; Thu, 23 May 2024 15:37:51 -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 d75a77b69052e-43fb18af1d2sm1066701cf.65.2024.05.23.15.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 15:37:50 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Jason Gunthorpe , Andrew Morton , Al Viro , Dave Hansen , Andy Lutomirski , Matthew Wilcox , peterx@redhat.com, Dan Williams , "Kirill A . Shutemov" , Mike Rapoport , Ingo Molnar , Michal Hocko , Alex Williamson , Peter Zijlstra , Suren Baghdasaryan , Borislav Petkov , x86@kernel.org Subject: [PATCH RFC 2/2] mm/x86/pat: Do proper PAT bit shift for large mappings Date: Thu, 23 May 2024 18:37:45 -0400 Message-ID: <20240523223745.395337-3-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240523223745.395337-1-peterx@redhat.com> References: <20240523223745.395337-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: 55B0F40020 X-Stat-Signature: ptz5mawn7aqk1rstjgzanai5jxrnco5o X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1716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yOI4nKVsMQ4DGVo2biJ0Cftlnr5taK/mFF3DaXQ5HuTaO1BR8hSNyQo4Nn+AmCPtlFgMmeAaEACjS5mECcxGpT9uzHehnQaDZqGbCl2mKtQUP9Of6ED6aLmuMVCU6+kx8LbI/2fmUDXTkCka9yLvBirqWzEYv0tM9etdpPXB6CsSF6Gdknr9SqbzhbTnfHBaB705VCGXwAT8o/osIdgN6CW6uFhZqVdqae1yPHFQDmzf935VLIplFe3JSP0+BFzWMDLVbtbk8SMxkVxeAc5BYdMkNv05r+1zKcovrjRaEGe+TjYLVVWvH/JtltAm4D/xUe+ht0yB0h5TDE3mu42b9iaGOY8//saXkjhsuxHmpul6e09CY461prPqJKVaEGlq5R7yHxiujboFgpPdC0qkvQ8sBTTKBGTgRbFYEublKskfTp70WMDDh6uZ6fmv05Xqm9Kz/g55aSVwCrsXq73TSX3HW4a2/XeWH7hq20TqAhqCsZ0t3R0Ljk2X/tUacIx6eBrOXpkpuClKjgyQsWLBWlKxaY8pQtXwbEP/MfHdcTW6/BYk/avvhLqI+wEEOWm7G9LA/Xydn2dQOWDYYW7vGLAM2bCfD57VKVMkm0bmGSFNsvwfk1NOwmsKw2RmOkLcQ8Bv7bY 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: For large mappings, the pgtable PAT is set on bit 12 (_PAGE_PAT_LARGE) rather than bit 9 (_PAGE_PAT), while bit 9 is used as PAE hint. Do proper shifting when inject large pfn pgtable mappings to make cache mode alright. Cc: Alex Williamson Cc: Jason Gunthorpe Cc: Al Viro Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Kirill A. Shutemov Cc: x86@kernel.org Signed-off-by: Peter Xu Signed-off-by: Peter Xu --- mm/huge_memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 317de2afd371..c4a2356b1a54 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1135,7 +1135,7 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr, goto out_unlock; } - entry = pmd_mkhuge(pfn_t_pmd(pfn, prot)); + entry = pmd_mkhuge(pfn_t_pmd(pfn, pgprot_4k_2_large(prot))); if (pfn_t_devmap(pfn)) entry = pmd_mkdevmap(entry); if (write) { @@ -1233,7 +1233,7 @@ static void insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr, goto out_unlock; } - entry = pud_mkhuge(pfn_t_pud(pfn, prot)); + entry = pud_mkhuge(pfn_t_pud(pfn, pgprot_4k_2_large(prot))); if (pfn_t_devmap(pfn)) entry = pud_mkdevmap(entry); if (write) {