From patchwork Fri Aug 9 16:08:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13758931 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 530BDC52D7C for ; Fri, 9 Aug 2024 16:09:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A57306B00A4; Fri, 9 Aug 2024 12:09:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E0F56B00A5; Fri, 9 Aug 2024 12:09:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82E4B6B00A6; Fri, 9 Aug 2024 12:09:32 -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 638D16B00A4 for ; Fri, 9 Aug 2024 12:09:32 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D88821611DC for ; Fri, 9 Aug 2024 16:09:31 +0000 (UTC) X-FDA: 82433192142.06.524A70C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id C10551C0019 for ; Fri, 9 Aug 2024 16:09:29 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gBd4TJUh; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723219760; a=rsa-sha256; cv=none; b=TQrtKJCCwO/wZEUipItbHbig9hDX/qbPEwSL0lzReN9F8QiBD1N3T+PNmxDOTMx2wnO6sr 5ki7izgY4oG1bdu0JHTcOutxm9Z8A4P+MO4dpwSJSPuccquvpMiwpnQX8cG0i3CBrSA5yo dXWSb8S6uPZI+c4uH7ABHKRki4Ofh+8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gBd4TJUh; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1723219760; 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=bfMsI243pXvbDIYk3LIHdKnZKRp0h0WHhTX8nwPWLTI=; b=E6lnnL4y01RX3OkhxgQU+If21p/p70dFYSiw8T3ZaQxo1EkdT9fIlYL4v9CpG0XJS974p0 k2RiK0Y1DlgV7EyEumVwc1ozdfrmvbaqNugI6G2zhFfjJT16WjkTHYC1U8E4HOCdlAwrh5 g/knA7t/M/PsGMcJv2w5Oubz1nWiKPI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723219769; 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=bfMsI243pXvbDIYk3LIHdKnZKRp0h0WHhTX8nwPWLTI=; b=gBd4TJUhLvNQDYh1PUDUgel3bAtJU85/efPnUWHoaHH9sH1Agh0YmjeA2xolzfHxVEWxaj jXi8Qent0c1uqpyE4/KJasL8B1HC+HLtctnOFbrSP5O8JGu3QD6iC6fDKjolgG0ZX4XpW9 5PbJfmW8O0jT8Ttx8EEUJCWm3MeZzOs= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-360-s7knL5dfMNSYK9X8TR5dnw-1; Fri, 09 Aug 2024 12:09:28 -0400 X-MC-Unique: s7knL5dfMNSYK9X8TR5dnw-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4531adc3c76so35861cf.2 for ; Fri, 09 Aug 2024 09:09:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723219767; x=1723824567; 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=bfMsI243pXvbDIYk3LIHdKnZKRp0h0WHhTX8nwPWLTI=; b=Pun9UwELgT7qvSz4Ihz2f/6n5fRX6cRkwLtwUT1YFKlBtqNcyzdl4Os4w+PPMuG9E6 yYd6fwkkidQzQ3nYjaBXcpG3NNe0YP1tQt2v3yEqQ7uqomk8y1GFSOULTNfBZR/OT1UP m1Cfpb2Mn/fzfijYgW+Bgi8dlKQ3b5GIInN+UGHUDTOujDAk11ObcYzQ2TAw2d8DRyhV FJ3rOGHaIahMIqixYMOj0P3FEKiK4jO4HV89d/lH6zUEHr5BJQ4HfLA4C482Qk1TaAEo sJMunSy4SxNMsSmpew4Mwxe5e8Z+1vFBjKDxqIKJJeutyjaKK2bYkWiJkWRAx9bljwRp 7mow== X-Gm-Message-State: AOJu0YwmqE6a+cLvNQgPd9s/OAjaYx3ldlAvE040I3ILkZFhsgPdbRqm Ybgf/w8KiukODhtQjSRaMF837ScS55NmQ2m8TyK1B7VlNMIPJeveABJxCM1uQtGilKs9djN/9fN VZDN/IgQY+6R/5yD5bUZy0qjnhq1VJozya30Gowlf1SIHrYKjYxavylsxJCh33hKzQ22rQU46F9 WXTlKtSPOeUpspQ4coc4eEpx1N/DGJ8Scg X-Received: by 2002:ac8:59cc:0:b0:44f:c953:290d with SMTP id d75a77b69052e-4531251d17bmr12886321cf.2.1723219767164; Fri, 09 Aug 2024 09:09:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElkbLJ8q6bD88BtBGZOYKdaksYNPrmA3JWwjtOEQ9+GQ5ZX+OpUCG/V8WuVaLDdrJFvk6CQQ== X-Received: by 2002:ac8:59cc:0:b0:44f:c953:290d with SMTP id d75a77b69052e-4531251d17bmr12885751cf.2.1723219766412; Fri, 09 Aug 2024 09:09:26 -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-451c870016csm22526741cf.19.2024.08.09.09.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 09:09:25 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , Oscar Salvador , Jason Gunthorpe , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, peterx@redhat.com, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , David Hildenbrand , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao Subject: [PATCH 05/19] mm/gup: Detect huge pfnmap entries in gup-fast Date: Fri, 9 Aug 2024 12:08:55 -0400 Message-ID: <20240809160909.1023470-6-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240809160909.1023470-1-peterx@redhat.com> References: <20240809160909.1023470-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-R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/ I/AzD+3u gO+odi30zN+26Ysr0S0Z4zbYyLd0N0aYUNwjlRy8IhC+FIlFCl5IKWY3uGt0GQ0QX44yzMJje3FzlvLKiLiEAJsFJTCbfiVMg0Eu6Lfkx3C/wBED8EweMmIWzFxaFVRoVyXoKwYpkIUAs8lD5+bi0gXetG5J3/4F67cnuhjV9re4T7jSU+18flJ2RrMpV9vu1xAilK4k7kl2iAYx+0cxAfuVgc8Rzkm2kw0MQnH9fnZcXA5t8JMy/yM3TsUTWvQHfahDQn/QtUB5lEsECooTYDp8Zpn2Inef/xR1AGYeZfNFbvYfFx1JzJsqtO15d3JL+apxQ4wWV2lgtSVgYDwNULqry1EO2O22erbeLFS9G6tOKSKPN/XLWWWIbiV7NC/KB0zVbx1K7UPXaGtR7NbeCGTjLHmikLKI233EFomn9ovPNjcslyrGQyPVJBIpZICVB/y6JuzvBbBvO3jE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since gup-fast doesn't have the vma reference, teach it to detect such huge pfnmaps by checking the special bit for pmd/pud too, just like ptes. Signed-off-by: Peter Xu Acked-by: David Hildenbrand Reviewed-by: Jason Gunthorpe --- mm/gup.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index d19884e097fd..a49f67a512ee 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -3038,6 +3038,9 @@ static int gup_fast_pmd_leaf(pmd_t orig, pmd_t *pmdp, unsigned long addr, if (!pmd_access_permitted(orig, flags & FOLL_WRITE)) return 0; + if (pmd_special(orig)) + return 0; + if (pmd_devmap(orig)) { if (unlikely(flags & FOLL_LONGTERM)) return 0; @@ -3082,6 +3085,9 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr, if (!pud_access_permitted(orig, flags & FOLL_WRITE)) return 0; + if (pud_special(orig)) + return 0; + if (pud_devmap(orig)) { if (unlikely(flags & FOLL_LONGTERM)) return 0;