From patchwork Mon Aug 26 20:43:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13778399 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 A67C0C5472E for ; Mon, 26 Aug 2024 20:44:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDC0B6B0095; Mon, 26 Aug 2024 16:44:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3D946B0096; Mon, 26 Aug 2024 16:44:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 969536B0098; Mon, 26 Aug 2024 16:44:13 -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 77FF56B0095 for ; Mon, 26 Aug 2024 16:44:13 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 85432121396 for ; Mon, 26 Aug 2024 20:44:11 +0000 (UTC) X-FDA: 82495573902.12.908F827 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 6A08F100010 for ; Mon, 26 Aug 2024 20:44:09 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RDyPqAPJ; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@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=1724705030; 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=SFHgAMnpeJHqDMa0ADr1pyvSduy44GuxF04BOe5aqcw=; b=tk3F/dzoxBNHnXoj2anCJP23mKs9Ou2aL8I2xbw38wIGivyi5B+PU/+AtcHRnpmEEpJL5J M7jo/8RrOYW2BrKBXZsvJrVjt1gSKefFdYtlx7haWP6YhwwiMm+TPq3k5mgT2VxaSVvCd8 6c10NKladnuPPSSdVdRFWO8M8mhbun8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RDyPqAPJ; spf=pass (imf14.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724705030; a=rsa-sha256; cv=none; b=KYloQ05GN37RI1ZpnueCZf0JnWZLeuprdFZ7XjdM1KkaWkgN35mrSMI/1PYqaCP/BYgtcU bjoAWfGiZ8yEIDh2/HCdlxVQSTOVKWdiy6UcMmzh9sLjk6lvch48uyhAP16QCs7HGbOv3F S9cFyZTEr7jC8rM3+X9tvqHDmHhO9k0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724705048; 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=SFHgAMnpeJHqDMa0ADr1pyvSduy44GuxF04BOe5aqcw=; b=RDyPqAPJHjgBfMYKmTCGMBroxlyMfFK3yWgJNGM01HLl/lo7WpU0QM2/UERzvl+jtYRAX7 fhRHO3tv15uHXbqjSV/AaoHESndNf+7fTrlijp+/PQWyLuNm3wXxDlDXFNSdcEq1WFOyUZ y3XXA5TOL6ttYJmuzXcqDdXUWv8Ct9g= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-zByFxE3OPJGmx1HM3_02jw-1; Mon, 26 Aug 2024 16:44:07 -0400 X-MC-Unique: zByFxE3OPJGmx1HM3_02jw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7a1db42803eso699490285a.2 for ; Mon, 26 Aug 2024 13:44:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724705047; x=1725309847; 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=SFHgAMnpeJHqDMa0ADr1pyvSduy44GuxF04BOe5aqcw=; b=om8YnGrJL4lKKxVeKmZ41BPj8bXUimHdBEHgyWoKQY2HQSAUIPhikuwFmW6oWBHYIr k6Mp0gKEbz2zstmsWj0Qmp8q7o0ninDj7RIxcBYFB739Q2E35neUhQvAAELIaloegzYD gdB0h+KjK2v4GOquCJoxXWxmeN0BI5VcjEr3y/BSdP2Md/vdlG9JBXfqyIXwdr4Z1Jre ws3VGhKONL0J6XPFeu6GZw+Wig9Rkz/A0D+8b0xwP4MJevNoQhFoVbK92zCMTqWqr7mz sCNeJtnT61OQEY55Cw73MCvUc6EUwr832GDpD1CiYp8AIlRfCwBwblQt8lXp3/hwNMHB Z2uw== X-Forwarded-Encrypted: i=1; AJvYcCXbIORkNULKn0JLO0GnnCjOdc3E087R3y4PS1IbrYgc17O3JbQduwR3UmiJVbCYSyQ8Fs7R2iT9rQ==@kvack.org X-Gm-Message-State: AOJu0YxX0j9R8Sf4IroMatQ/HyFyYRejOMhLiHtHLzyK/lQ4mbxhQGbR 1aBQhTjF/AWJKBAlN/VHoyocrnIt4V6wH8NpLXlMSUOkN+qJodvbY4Wqp8cgFX6b87Zc9IlVb3M 5dsAp16AgSO+HCOYD8ssRSoAjQkOUlxe/lmQ/tf006zwSe5yX X-Received: by 2002:a05:620a:2a14:b0:7a2:ccd:9672 with SMTP id af79cd13be357-7a7e4e6144fmr67568785a.67.1724705046879; Mon, 26 Aug 2024 13:44:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG++rZwRsHPi3LEX2hBpbUb+Bhnwx97nv6F7Fy5QJm5RgQYxXJ7nF8aD8ykhSm+rXvWrvbUzQ== X-Received: by 2002:a05:620a:2a14:b0:7a2:ccd:9672 with SMTP id af79cd13be357-7a7e4e6144fmr67565885a.67.1724705046455; Mon, 26 Aug 2024 13:44:06 -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 af79cd13be357-7a67f3fd6c1sm491055185a.121.2024.08.26.13.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 13:44:05 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Gavin Shan , Catalin Marinas , x86@kernel.org, Ingo Molnar , Andrew Morton , Paolo Bonzini , Dave Hansen , Thomas Gleixner , Alistair Popple , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sean Christopherson , peterx@redhat.com, Oscar Salvador , Jason Gunthorpe , Borislav Petkov , Zi Yan , Axel Rasmussen , David Hildenbrand , Yan Zhao , Will Deacon , Kefeng Wang , Alex Williamson Subject: [PATCH v2 05/19] mm/gup: Detect huge pfnmap entries in gup-fast Date: Mon, 26 Aug 2024 16:43:39 -0400 Message-ID: <20240826204353.2228736-6-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240826204353.2228736-1-peterx@redhat.com> References: <20240826204353.2228736-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Stat-Signature: 54u5ngu44bherffao56z6ba3h97ms3cx X-Rspamd-Queue-Id: 6A08F100010 X-Rspamd-Server: rspam11 X-HE-Tag: 1724705049-669219 X-HE-Meta: U2FsdGVkX1+AK9SFeImQvfHuQV3rfh9/zEGqdu2mTh3kl9HVqEibu3DMd8y7T/MapT0El2+mar8Y41BDM6oaoydfWQn8ZrOJVG/YW3vuSRe/FvtNmv9+v2ftvZF3wL6co7O+BepGUn4QpCTHbjre2RLRbqp+IRhGbbD/11AjvWZvYRGB/b97isExM+eGf7SUYmJjWLY/b9Fv4D3uPQkZj/FWiSptnc2y16mslh4RKhupXEuRYWQmkdGfkx54bgT2IXw18rCimEKG9ByPUgFgoSLX3Od60lFa3V1p7puzngMxYSfBT4MJILI8/oo7xT1cXqeOBiIHgTLHKrdPAHPC7JwlezVvaOtWN5hDZpHdvw0dAjxVtLBFUfVmpuuL60GG04JRxSskdz05eH/uE3nNi5XjQd6i57VqqSFpikRtjA0quuBVdKI8UKqa3FNSVNmSCzH8nHkZ813v3OK4dHcXszw9s7Ta4KHkV3MPhOzuPJW3K+v6n7z/MPTkCczp1axRuERBbGlpjucckek46macSHgbwotyKxiJC0swoUNUa9KsUE7Cm2mFEBauP/M0tupqKRGspJmqD33paqOqDjPETyVYJxU31nOe9yMKDURGQ3WFNkJ1AFAQT7/+G57l6g6Pnv8aFPSlaUbzw5Dn5J5hfZun+p66/dmKaKpqH/8OWaC1on4u8UxE5mBvvi0Zag01Z3BZN7NJeN3BSyzoyTnI4cCVMX2JjlzkCaCUGbL1ogunYgs92W1UhZN3gRJKkKY5Vnyz2qlK7V2QWSoUDl7WPgOh20j4RoCDf0+bk7ioagwEVE2PJnasBnQmPfIGADFaYYeSx4QNOEJqyb79f0kCxJdiQ560GbCfa8SbRsyCD1y+mYjeSxp6c6P5JggUUQtkZ4RhezW0LX1axX3dZ5sSM3LPUS7iUvSUfDKMgQLfWSBUFyxgCzCv7BUdGxCSd3vOHp9oqVGIoSbiRpfOLbk HPVT2S+t zDNAI4xZv8TVL5XS/skScZEf/1z2imvSX8uCMFYn+ElyZS+y5AooVCB/iCaZ63mHLqcbiDNa4o9t4/LAMu5QAn22NEuBeP0P9SvoFpnsfAjq0o3Yirevyw0zm5mzt8yUa4DMrwFwSDJZl9peAf3+9M4z5+Vi8Ub5zheKLYc4BAOU94UDyefkruemSe0GFV8Qp1jJ14P/cfYzlDZWo/tVZmm1f4+yztKb6A+4SZFIoT79Zcza+OdjGMu4ant4ifEwcLHwi1ddOrLeMVdzCszBFQtYe4p/uMDD7HfFVo4v5Zb4IMBfJ6dbniWKi+sl7oW+Uvm+DgGyUbbYu8ZSxmfgz2a+JmhCNaOQj6oa9WtJnwANOU2U= 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: 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. Acked-by: David Hildenbrand Reviewed-by: Jason Gunthorpe Signed-off-by: Peter Xu --- 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;