From mboxrd@z Thu Jan 1 00:00:00 1970 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 5FAE3ECAAD5 for ; Sun, 28 Aug 2022 12:38:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70570940007; Sun, 28 Aug 2022 08:38:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B4A46B0074; Sun, 28 Aug 2022 08:38:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55573940007; Sun, 28 Aug 2022 08:38:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3EDD16B0073 for ; Sun, 28 Aug 2022 08:38:05 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 04941407B1 for ; Sun, 28 Aug 2022 12:38:04 +0000 (UTC) X-FDA: 79848953730.25.84C1F88 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 4B1F416004D for ; Sun, 28 Aug 2022 12:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661690283; 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=YWZ0OCc6Jw8ZV0oLlM1p01dda6gQGAes6Y+jsvNcrnc=; b=PAq/Q6aTfvHZxDncpWTqjZeHS1iPrq6G0oBR3bYrosdDnYF3coWxXAohzRvLzPlpQYVGWg ulZsXBgxwB5777P2OR82f4aIOW6hOC28ituOkHZ+TErYC/FbRm9fzcUYZzdx3PWc2+ULKv fxRoxZf/P6DZtqtFUFRy8VgXWHfMUJU= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-665-H8zTSFRHOSuBWgdyMTsIQg-1; Sun, 28 Aug 2022 08:38:02 -0400 X-MC-Unique: H8zTSFRHOSuBWgdyMTsIQg-1 Received: by mail-io1-f71.google.com with SMTP id q10-20020a0566022f0a00b00688d703717bso3256704iow.9 for ; Sun, 28 Aug 2022 05:38:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc; bh=YWZ0OCc6Jw8ZV0oLlM1p01dda6gQGAes6Y+jsvNcrnc=; b=sUTkL6pKeXWQ/qR2SKlr0ID9yOmX7uBQKmGI7et2qrmcezcMRczzDPnVPFQpE60eGc OvSorlx9V7R5i2gsjUUTVy/Y0WenhbOKwXkc01GNxhcXsvZqQGyLaj3w3PZdvMpViTOW F69GT2cUQF1vsGXMP0GMJ/IyhyNpdhAYjMLKlzK4BXWrwV1cS0T6AHIZSwWSFKWXBTrx pOQlQn/aG/3T0GiEUVNl/YdWICTn1JIqxN4cMveEfuRi7tpAiOKMQYgaq9S6WyyQgSsS VjOnfXMH1CoFLb+hTy+RGh0hHTffwuFGAfRMGcLrNupSRYMWnunE5f+WPAAd4REKORL4 bhEg== X-Gm-Message-State: ACgBeo3g7+B2LOB/eIx+w9p66jaIZAnonCjuYCua+nNkllWpOLPANRFp 1KT0bvl5nnwpQdvMzxqvj9O3hsq05dIDAbE7ogeGXfiHMSO3ZiVBB9+UWGIrOGJ2IRyJzBpC41G JMV17VCjYV/c= X-Received: by 2002:a05:6e02:1b09:b0:2df:1c60:e428 with SMTP id i9-20020a056e021b0900b002df1c60e428mr7666596ilv.227.1661690281950; Sun, 28 Aug 2022 05:38:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5px5ANkM8ZpE9nMa44q0u7kj+R2zpLrObamHUIS2ILRuz6ZAXI92T9u3hhTeKSU/8keTmlzQ== X-Received: by 2002:a05:6e02:1b09:b0:2df:1c60:e428 with SMTP id i9-20020a056e021b0900b002df1c60e428mr7666578ilv.227.1661690281729; Sun, 28 Aug 2022 05:38:01 -0700 (PDT) Received: from redhat.com ([38.15.36.239]) by smtp.gmail.com with ESMTPSA id d9-20020a023f09000000b00349eece079dsm3121665jaa.35.2022.08.28.05.38.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 05:38:01 -0700 (PDT) Date: Sun, 28 Aug 2022 06:37:59 -0600 From: Alex Williamson To: John Hubbard Cc: akpm@linux-foundation.org, 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 Subject: Re: [PATCH v2] mm: re-allow pinning of zero pfns (again) Message-ID: <20220828063759.60c85fd6.alex.williamson@redhat.com> In-Reply-To: <033c2e8d-8ba9-3e0b-9dee-7d0973c708fa@nvidia.com> References: <166015037385.760108.16881097713975517242.stgit@omen> <033c2e8d-8ba9-3e0b-9dee-7d0973c708fa@nvidia.com> Organization: Red Hat MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661690284; a=rsa-sha256; cv=none; b=UVaEHjZSKIJsDwMSyKWnWvq3FDrNvgAOyR746lsLqQahtWdIyFHKmQCIx7zVDFifPb7h4r bZX/Wceo44tDCnOZQyRNf7K7pypzcCvU+pkFRdjcz5aqkuamiyoTOs3N/bVuAzBscnYPsG Dow3ufWAfMDxUKN9XYXSFbbKiI2A4iE= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="PAq/Q6aT"; spf=pass (imf08.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.129.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=1661690284; 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=YWZ0OCc6Jw8ZV0oLlM1p01dda6gQGAes6Y+jsvNcrnc=; b=oYmUVW9pumBGfOkQRKbEyEstGV4MleOhCf7FJNi9M7PXLo9kgr6IQfY1vm+3xe9Sva43TF BGXKPUOuVJMaqM7mTdVUqpjZhmd5g62iBqqMhujBO3lX1CXc8GCEOtjQCCuKEQbWpSlVOq +o9ClbRET5cuulxmTaTjcV8h0fyOtT4= X-Stat-Signature: sbbomtu14i7179xdwud11ug6ipw4godx X-Rspamd-Queue-Id: 4B1F416004D X-Rspam-User: X-Rspamd-Server: rspam06 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="PAq/Q6aT"; spf=pass (imf08.hostedemail.com: domain of alex.williamson@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=alex.williamson@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1661690284-942403 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: On Sat, 27 Aug 2022 17:59:32 -0700 John Hubbard wrote: > On 8/10/22 09:53, Alex Williamson wrote: > > 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 > > --- > > include/linux/mm.h | 17 ++++++++++++++--- > > 1 file changed, 14 insertions(+), 3 deletions(-) > Hi Alex, > > Looks good. I'm suggesting a simpler comment, below, because > even though the VFIO folks are thinking about VFIO, here we > are deep in the mm layer and there are lots of non-VFIO callers > that may pin the zero page. > > > > > 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. > > + */ > > Those notes are all about (some of) the callers. But it's a simple > answer, really, so how about just this: > > /* The zero page is always allowed to be pinned. */ Sure. Are we looking for a re-spin with this? I see Andrew already added this incremental change to his hotfix-unstable branch separately. I'd hate for a comment re-spin to delay getting a fix for this problem, that blocks any VM use cases of VFIO, into mainline any longer. Thanks, Alex