From patchwork Wed Aug 10 16:53:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 12940778 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 20937C00140 for ; Wed, 10 Aug 2022 16:54:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A28CC6B0071; Wed, 10 Aug 2022 12:54:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D7B68E0002; Wed, 10 Aug 2022 12:54:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89F458E0001; Wed, 10 Aug 2022 12:54:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 78BEA6B0071 for ; Wed, 10 Aug 2022 12:54:05 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4F3B9160653 for ; Wed, 10 Aug 2022 16:54:05 +0000 (UTC) X-FDA: 79784280450.10.AEE8FCC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id DD2F340184 for ; Wed, 10 Aug 2022 16:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660150444; 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; bh=TTGWzxCjDJzoBTfs7PLy6BgM0SdljH8TTEXTgLlppnY=; b=X0Zceq+e0zBR3l+veAHrTWB+M9UkarbAETEti/C5CfXr+1NU5AodOQ03AS6wCV2G/8ugFa HrnEtnpPXIGUxirsoOYTbngH1pSMhpXBFRVVvkHVAKXq2eCVqm7L+V2uWYrvZuPp4v95tn gPa1n37PUSwr+XcPVoW9pbZh/7YlSBg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-386-Nc8QxchhP2qL872tcXFedg-1; Wed, 10 Aug 2022 12:54:01 -0400 X-MC-Unique: Nc8QxchhP2qL872tcXFedg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B60F803FFA; Wed, 10 Aug 2022 16:54:00 +0000 (UTC) Received: from [172.30.41.16] (unknown [10.22.18.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFBA240CF8EB; Wed, 10 Aug 2022 16:53:59 +0000 (UTC) Subject: [PATCH v2] mm: re-allow pinning of zero pfns (again) From: Alex Williamson To: akpm@linux-foundation.org Cc: alex.sierra@amd.com, willy@infradead.org, hch@lst.de, Felix.Kuehling@amd.com, apopple@nvidia.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Wed, 10 Aug 2022 10:53:59 -0600 Message-ID: <166015037385.760108.16881097713975517242.stgit@omen> User-Agent: StGit/1.5.dev2+g9ce680a52bd9 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660150445; a=rsa-sha256; cv=none; b=qjkjoCBGC2nUxOm9wOjC8Pdm38EF+YiO2RMni48uMdENsAYLFSUg63RRevfX9cYJvqzmh+ 08zuTsSfiz77L9U7yiHaeUKhFnZXzDbHwIwXW+lSXVYcNvMzpPBJJPir/l+dOT/dGgdHsV m4jKeNAbC32zQMC9N49lBJM38PjqyIo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X0Zceq+e; spf=pass (imf12.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=alex.williamson@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=1660150445; 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: references:dkim-signature; bh=TTGWzxCjDJzoBTfs7PLy6BgM0SdljH8TTEXTgLlppnY=; b=IN8oIsovXCyJ5IIjypQZ7wwcTlDss39+zX/T+LEAmwqkShw+EyGOjshBpw7U1P0k7CyE6C gob+RvhTIwwOuy1b/TFyNb5NlV5Bo7mX5wBlmKN10prmIoYzWtX3+X4pXjCgvze+A8ePyB zXfmdDw1VPQ5xLFd2qHXGn/DMu0Dm/s= X-Rspamd-Queue-Id: DD2F340184 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=X0Zceq+e; spf=pass (imf12.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=alex.williamson@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: 7t3qbp1joerpk14owidpgac1g8h5yeea X-HE-Tag: 1660150444-361514 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: The below referenced commit makes the same error as 1c563432588d ("mm: fix is_pinnable_page against a cma page"), re-interpreting the logic to exclude pinning of the zero page, which breaks device assignment with vfio. To avoid further subtle mistakes, split the logic into discrete tests. Suggested-by: Matthew Wilcox Suggested-by: Felix Kuehling Link: https://lore.kernel.org/all/165490039431.944052.12458624139225785964.stgit@omen Fixes: f25cbb7a95a2 ("mm: add zone device coherent type memory support") Signed-off-by: Alex Williamson Tested-by: Slawomir Laba Reviewed-by: John Hubbard --- include/linux/mm.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 18e01474cf6b..835106a9718f 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1544,9 +1544,20 @@ static inline bool is_longterm_pinnable_page(struct page *page) if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) return false; #endif - return !(is_device_coherent_page(page) || - is_zone_movable_page(page) || - is_zero_pfn(page_to_pfn(page))); + /* + * The zero page might reside in a movable zone, however it may not + * be migrated and can therefore be pinned. The vfio subsystem pins + * user mappings including the zero page for IOMMU translation. + */ + if (is_zero_pfn(page_to_pfn(page))) + return true; + + /* Coherent device memory must always allow eviction. */ + if (is_device_coherent_page(page)) + return false; + + /* Otherwise, non-movable zone pages can be pinned. */ + return !is_zone_movable_page(page); } #else static inline bool is_longterm_pinnable_page(struct page *page)