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 D18CAC19F2D for ; Tue, 9 Aug 2022 14:51:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 487776B0072; Tue, 9 Aug 2022 10:51:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 436438E0002; Tue, 9 Aug 2022 10:51:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FE608E0001; Tue, 9 Aug 2022 10:51:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1F5246B0072 for ; Tue, 9 Aug 2022 10:51:35 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DC5411C5B28 for ; Tue, 9 Aug 2022 14:51:34 +0000 (UTC) X-FDA: 79780342908.21.6EFDCBD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 7E83A400B4 for ; Tue, 9 Aug 2022 14:51:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660056694; 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=vfc/XL1jm/fZbt5EGR6fy3ohsW4Si3tCDlCcEICIpkw=; b=GromvTBn+dqbpHIlXTpwyNbR8LrDUk0JUc4S1b1zppEhmvSg2iRs9v6sgxjS7wxITNGtdK Z8rFzDjarXzOyCrRczrswM7t5sfmyRIDAR2S2U1eUZFMPRRz4S7S1+NiW7GW1h+DyhiZA1 mh6+PeRuF2AkWCfFjXvuKFfRUnZpjUc= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-Qwku_wDjN-unZByKJRrxDg-1; Tue, 09 Aug 2022 10:51:25 -0400 X-MC-Unique: Qwku_wDjN-unZByKJRrxDg-1 Received: by mail-wr1-f70.google.com with SMTP id u17-20020adfa191000000b0021ed2209fccso1888545wru.16 for ; Tue, 09 Aug 2022 07:51:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=vfc/XL1jm/fZbt5EGR6fy3ohsW4Si3tCDlCcEICIpkw=; b=tl6zcAFQSZ9OCj9K03d4elqRFilO67R/iROoUd3Bim3kO534U3o1TJlfrW94/q5cfl GTu1Fi3BsUysOnmsyjUh4mrw7vpzSDDSh51NblDlOg9rDpIBxeMY4Gib7KlzOTE6JnnL 9H8w4HshFCqbgoai4YfrH7sMX8uj9WJLSSJ0hogPTuas4Ly4xSnWLW1wVFfj1QZiD10y IqIKEbVhx9ONShhDb41opxfm75os6zHm/Y11Gm8Vk8PUAiI2mAnzoYuwbFMjkXP8Uyff i3rkXC4iQUhU8y5cJYtV0GmAa8dnXmh57b7BmxylVTEnQp0ELfsca3uLEjOhUTy3XxI5 UJPw== X-Gm-Message-State: ACgBeo1TPCc7LcVVx+aYDY9uyPq/9z40/ZtwUz4SX+Nyn19d75/o3ZMT 2sbB1W2jgMmYWThGvh3YhvLzqxphi3zH/dINpUTfvFMwDBtITaLRU0yixcz+4W/2h+1Cb124CaZ Ef8xlwWYIuTw= X-Received: by 2002:a1c:f618:0:b0:3a4:e569:946b with SMTP id w24-20020a1cf618000000b003a4e569946bmr20667247wmc.106.1660056684253; Tue, 09 Aug 2022 07:51:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR7qwhy4StXqMQoTGiKwluARjwk2LuQfdIRMp6P8vtwj6ysi8BYdYLz5aTzHIHq5y36BEje+Cg== X-Received: by 2002:a1c:f618:0:b0:3a4:e569:946b with SMTP id w24-20020a1cf618000000b003a4e569946bmr20667225wmc.106.1660056683937; Tue, 09 Aug 2022 07:51:23 -0700 (PDT) Received: from ?IPV6:2003:d8:2f15:c300:d2ce:1fb5:2460:179a? (p200300d82f15c300d2ce1fb52460179a.dip0.t-ipconnect.de. [2003:d8:2f15:c300:d2ce:1fb5:2460:179a]) by smtp.gmail.com with ESMTPSA id j4-20020a05600c1c0400b003a31fd05e0fsm2614814wms.2.2022.08.09.07.51.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Aug 2022 07:51:23 -0700 (PDT) Message-ID: <2dd8a91b-7d88-5847-3e7b-1315fae9ecee@redhat.com> Date: Tue, 9 Aug 2022 16:51:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] mm: re-allow pinning of zero pfns (again) To: Matthew Wilcox , Felix Kuehling Cc: Alex Williamson , alex.sierra@amd.com, akpm@linux-foundation.org, hch@lst.de, apopple@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <166002010021.381133.11357879752637949308.stgit@omen> From: David Hildenbrand Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660056694; a=rsa-sha256; cv=none; b=UF+SXfo5QAH7WwnPWPugAj8cvNMFeBSKReLSZCuPuZC0kY417TMtOjb9pJ2itfGqwDVroM jrc6xLVDLf9bL/Go9YRWAyjAs0M0quP0TGBOUCOB7gHyc9BLL61RCedJUo95Ct4+RBnCef W+eQM8p1CV7gC2ILikhygzy5saskHvw= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GromvTBn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660056694; 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=vfc/XL1jm/fZbt5EGR6fy3ohsW4Si3tCDlCcEICIpkw=; b=qMDvdxy4641Q+Itlgvsm1zX/FBEE/Gu/gGk1L1Kn2VehxZiOWuXNpA2uoch0o0wk+gGhWm auMcdK5wIj3KpDGanKNPiYyFd5K0heoialG/hehoIm4BOgbOkU8kiWKi6BYXX4QfVRQ4hi cvj543EmkrvsGYBU0IciZYffN1yc4PE= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7E83A400B4 Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GromvTBn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Stat-Signature: jkiqg9kdfc4dixpsgy3pmrgxfhsm9msk X-HE-Tag: 1660056694-136176 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 09.08.22 16:43, Matthew Wilcox wrote: > On Tue, Aug 09, 2022 at 10:14:12AM -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. >>> 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); > > It's definitely true that the zero page is never device-coherent, nor > movable. Moreover, we want to avoid calling page_to_pfn() if we can. > So it should be the last condition that we check. IIRC, with "kernelcore" and/or "movablecore", the zero page could eventually end up in the movable zone (whereby we can have boottime allocations being placed into the movable zone). IIRC that's why we have to special-case on the zero-page here at all. So taking out the zero page first is correct. -- Thanks, David / dhildenb