Message ID | 20240523223745.395337-2-peterx@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 <linux-mm@archiver.kernel.org>; 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 <linux-mm@kvack.org>; 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 <linux-mm@kvack.org>; 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 <linux-mm@kvack.org>; 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 <linux-mm@kvack.org>; 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 <peterx@redhat.com> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Thomas Gleixner <tglx@linutronix.de>, Jason Gunthorpe <jgg@nvidia.com>, Andrew Morton <akpm@linux-foundation.org>, Al Viro <viro@zeniv.linux.org.uk>, Dave Hansen <dave.hansen@linux.intel.com>, Andy Lutomirski <luto@kernel.org>, Matthew Wilcox <willy@infradead.org>, peterx@redhat.com, Dan Williams <dan.j.williams@intel.com>, "Kirill A . Shutemov" <kirill@shutemov.name>, Mike Rapoport <rppt@kernel.org>, Ingo Molnar <mingo@redhat.com>, Michal Hocko <mhocko@suse.com>, Alex Williamson <alex.williamson@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Suren Baghdasaryan <surenb@google.com>, Borislav Petkov <bp@alien8.de>, 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: E2A3540013 X-Stat-Signature: cnrmc9f5bct5nbqr6ywfks8fqyy5bx8w X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1716503873-954873 X-HE-Meta: U2FsdGVkX18vsnwl+I09SfmRDTN2fE3EJPlqAqPOvQWnIU0cAE+BzJYVyWB0v6dJLy204F+MzwVLmrOdavCmagtf2GnNVOlVbcPnoItsBiAqECROR/JFGe6cKviI4lntWvQi0pE9GTGjCWbN94aivxdAkKWSoMdg+nRlRipxddy5+80oCpIpX7hhrTZMTqUVB/A3ELKaVvukbua62Pxkr7wctBY1STvlx6Q3LZDbOT7ysTuZY7iHLN6ebhJQUNcoN/QxPmMwhCqcgJW+N3+yEHO15T6Y7GOJNCUI2ERTH2sfWlGB0nu3Gf6y5xUVye+Mzlv1HgKQtg1xVyDFXcqaeci4vk9eN/iHkwBPsCxmuN2IogNHcShhbuODouzZPDrP9xgttcQ/Xmjb8DMGktjHsC6cNe/5jMCEiu9SqA3rq0eQKpHgosGUaB/Ew/nC9lc6c/J6LAa1P7qGD23SZ1zmf6iKESqApzdGuEQ6UackNbC6AHVyfkWzXTeD6jyZ35NPUoVY/6XMwBmdsq6NKirlWs42ZbZxscJUBgFTWEsM9v6uhJ6cxIUHW9pE8gkVGsqlbF8eAY3CYFX0jWFkzIZEUHKcH580l/AmodsyX2y2iCkN/m4kC02i2YyHRMXj0tML2hPBAu9y1fsla0PH8RAxqNt/HPFq7mU767j//QkuggUUMyvAaLLqUipxXliG8RQzPeHQUcXtMOSVa9G0IYhfnUewA3KcVbs2q+ei1K+lolQhvFXKvJQesJAxWH9VJAIrug2kwO8LmVgfu3B1LRXy5uu8nZwReZgYo7Z9PIAyJYieZSDVfFw0QXualSv0KMWqxR0F2nbUw8mySMUI0Pi8h4VjaW4cq6+bPa6uqmkaVxudL2WeeS9n9utHDMbEHVvCVOGZLkNF4aOJXquS34TJhx2dnTlNjEW+jMS7JNQJRidALwzQJqACcFfErhO0kfQiTijH+BtKHya/w7Pgmao 46nHwYjJ 76KMYSqP+L7OQKND/53aE8bWZRauNbMLXlDZ5/TRV3o19RH0FQV8OxsaYU6A3Ff+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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
mm/x86/pat: Fix two possible issues
|
expand
|
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);
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 <alex.williamson@redhat.com> Cc: Jason Gunthorpe <jgg@nvidia.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Kirill A. Shutemov <kirill@shutemov.name> Cc: x86@kernel.org Signed-off-by: Peter Xu <peterx@redhat.com> --- mm/memory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)