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 24E60C19F2D for ; Wed, 10 Aug 2022 02:12:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A87D8E0002; Tue, 9 Aug 2022 22:12:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 757818E0001; Tue, 9 Aug 2022 22:12:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 61ECB8E0002; Tue, 9 Aug 2022 22:12:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 521A68E0001 for ; Tue, 9 Aug 2022 22:12:32 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 286F81A04D9 for ; Wed, 10 Aug 2022 02:12:32 +0000 (UTC) X-FDA: 79782058944.18.A6EF235 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf06.hostedemail.com (Postfix) with ESMTP id B16F7180153 for ; Wed, 10 Aug 2022 02:12:31 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4BD81B818E4; Wed, 10 Aug 2022 02:12:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C390C433D6; Wed, 10 Aug 2022 02:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1660097549; bh=mk2uW891Ph7QCIkkZA5XSEm1+XrXQwcsEZKt1nJZdPM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=P2rdO5+8XuOckGFqAGCLmNVeQdyrR6LB7XD57kbDWblgOmnljFX/6hy/c2Pt/9ecE iv1yJUd/77YPr+rbu1Bq0dr/SsijaoRZHXZ4ByszNRZnUTMXhAAMV8q8/epG98iRmW wjaBbHrPBFmp7z7Ry9YlP5+yI5mY6zwPDe4Z8+IE= Date: Tue, 9 Aug 2022 19:12:27 -0700 From: Andrew Morton To: Felix Kuehling Cc: Matthew Wilcox , Alex Williamson , alex.sierra@amd.com, hch@lst.de, apopple@nvidia.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: re-allow pinning of zero pfns (again) Message-Id: <20220809191227.4694677c360c4a64164f7136@linux-foundation.org> In-Reply-To: References: <166002010021.381133.11357879752637949308.stgit@omen> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660097551; a=rsa-sha256; cv=none; b=Aa/mDfM8rkJootfPnMs88GYGh/0P6BA4fisbS+1eloicMjBy8imRbH9eB0jBquwzYuaUku HSXprbDt605wbK9NPxfCBgmEY9SaQ1e8Nl6f+ah6/9YVaRvZX41Uauh8i/y6NpOIyBS0wA RAFk5B+QWQrdZtydAejgC2McSFr2jwA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=P2rdO5+8; spf=pass (imf06.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660097551; 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=MiRq3/rLQlfj9JoYfXnp9Y20nuxkiG31rPgVbxkcqu4=; b=7BfHhVTMLwVEoXQbAvaw3RNNVtZFLa9bH0tnCGX0HZ+2rKl6MOXIWt2dlpbN4IlCgwYbUb 39kyiljbC3yR3Z7CNN1+6am4hwnbtdqlTxGgmSnxbPR5W5Axa9aHvLSwFmgT3vw0yv/YMy cm2HdVq0cgCyiWXqWOUG65HqaEZdSIQ= X-Rspamd-Queue-Id: B16F7180153 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=P2rdO5+8; spf=pass (imf06.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 3s4i64w49qztpha6n7ugeixk11t4spdo X-HE-Tag: 1660097551-761820 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 Tue, 9 Aug 2022 10:14:12 -0400 Felix Kuehling wrote: > Am 2022-08-09 um 08:31 schrieb Matthew Wilcox: > > On Mon, Aug 08, 2022 at 10:42:24PM -0600, 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. If two people made the same error then surely that's a sign that we need a comment which explains things to the next visitor. > > Perhaps we need to admit we're not as good at boolean logic as we think > > we are. > > > > if (is_device_coherent_page(page)) > > return false; > > if (is_zone_movable_page(page)) > > return false; > > return is_zero_pfn(page_to_pfn(page)); > > > > (or whatever the right logic is ... I just woke up and I'm having > > trouble parsing it). > > This implies an assumption that zero-page is never device-coherent or > moveable, which is probably true, but not part of the original > condition. A more formally correct rewrite would be: > > if (is_zero_pfn(page_to_pfn(page))) > return true; > if (is_device_coherent_page(page)) > return false; > return !is_zone_moveable_page(page); > Yes please, vastly better. And a nice thing about this layout is that it leaves places where we can add a nice little comment against each clause of the test, to explain why we're performing each one.