From patchwork Wed Mar 6 10:41:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13583873 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 074DDC5475B for ; Wed, 6 Mar 2024 10:42:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94CAD6B009A; Wed, 6 Mar 2024 05:42:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FDA46B009B; Wed, 6 Mar 2024 05:42:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79F886B009C; Wed, 6 Mar 2024 05:42:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 624676B009A for ; Wed, 6 Mar 2024 05:42:13 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 316E1140C2A for ; Wed, 6 Mar 2024 10:42:13 +0000 (UTC) X-FDA: 81866274546.29.AF745BE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id A8E8240015 for ; Wed, 6 Mar 2024 10:42:10 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GL254M44; spf=pass (imf12.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=1709721730; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=20nNimBrOEQv87l0vyMx8t0O66X6ZMzRQtOERvnhrUo=; b=YR94ceFBua48EasnTIUZVEzyRNGMh0+3QhfO4SBXKkYksewab8hPsvcvHKCCvvFz1RUpoZ R1HqqqYIYj5yV4aRIEHeF3zT8XV9sW+QWHmZcTBWbV3FQwBlOf/ccFh06y9uw8K7eCVT9A VNwH7xH88aq7j3K+Hu4xTTWjm4Thjlc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709721730; a=rsa-sha256; cv=none; b=qISrNK0++zzozKOFlMr0zKKqmcOCJ7gbE1yGvdXBoByulCisvyBppazinDyO3HFbA11nhe uuvRlb7y0y5YApfOVZk+114fr7tPrmQvLlgcyotCwhhGa8WN8bj5RHQh2bYfPU/DchztkN OZkKuDlPEZNouqAanrbtt/J8nx6ut2s= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GL254M44; spf=pass (imf12.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709721730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=20nNimBrOEQv87l0vyMx8t0O66X6ZMzRQtOERvnhrUo=; b=GL254M44hJe8AuZDn1fsdC3oAjkAu5DsCgTDeDFgBeNi2HktIM3VY/f1uKGmdDc4g6zwxc nRG5J9t+amnMkhMdZikbtDiIaaKWT1SvWO6Y7if/lOPTkAb195nRHz9xOszvO0ekUc3d4b HnKHW+TZgsE3k4oPzl9BVWbRfUWKqG8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-651-oo52lPpuOsCDdbHCtpeneA-1; Wed, 06 Mar 2024 05:42:04 -0500 X-MC-Unique: oo52lPpuOsCDdbHCtpeneA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7D471C05AF3; Wed, 6 Mar 2024 10:42:03 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C2C5112131D; Wed, 6 Mar 2024 10:41:56 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org, Andrew Morton , Muchun Song , Jason Gunthorpe , peterx@redhat.com, Matthew Wilcox , Mike Rapoport , Christophe Leroy , x86@kernel.org, sparclinux@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Alistair Popple Subject: [PATCH RFC 01/13] mm/hmm: Process pud swap entry without pud_huge() Date: Wed, 6 Mar 2024 18:41:35 +0800 Message-ID: <20240306104147.193052-2-peterx@redhat.com> In-Reply-To: <20240306104147.193052-1-peterx@redhat.com> References: <20240306104147.193052-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Rspamd-Queue-Id: A8E8240015 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 1wrmps7ambfarnrhkncm7ko3j7nnuhzd X-HE-Tag: 1709721730-587190 X-HE-Meta: U2FsdGVkX1/3ovT1VGqBspRlKzhTzRV0NxJG5Cnd29MGe5dLidUTzUFpkO47qfMDkjHkGVh64pPAAD3XwitJXDd+3QECuvuDhdiWsoKRkU+uQLyvGi9hhZnoL3HtMJKTvZ61up+5QuIBoLGrTuGoDZMaiyV0nks3I1HwrJ0AfNlr+4zku2cjUrnPcx+aDJlIQrLf+42ayiqMciUF0oAlDu41CQfGk8rYTAVBPS5pqOa41EcNMbqzFwYsVk1yvmp8NKQqwmKxVJNc59jA7IsGzAZQXbS2tVB17h1+I5/z1CgzK2u/8TNJB1MPKECy3quzX3hsOgPcsVJw5sg8bDcKF97cBN/fDc9WH9VTnncfXsgzlIsnHvhfCWTxm0cFUatrsWQ7YBDLEDQkbVbBnZ9DOSjr6YpyXwQ4z3C+msgckeCVvj3NJSVUk08NNnFP4TraxGJ/bSNBP9+T7SEToMADcKxQZ+jvAIpl5cI5mb6yoPO4FwkZwItEhHdxfJMVjWya2Sh5NCfjkc50mZVc87WA1+28RmqXly8dwq/rsAto+toqQlr3GMDl44yD2TOCUp9xUvtgLEaIy26JHeMAJjfoJIt4oY/K8aHbMfJAHMBgSk5YNKjVtSYDKyIxPhyYNpzS3ng0lANQyklD8abjPfOM7DwOS6jAJAvB+fB0Vbmacayfftplwpl+v8m9buJ7MO9amEgtE6Cuxj1jRwEMcJDxLT6m9Ju6G7BfPjv6qVkSURmBP9DFACNAeOScv0lzoHBgU45DR90AwRgPrMNEZOljvrHu7Im0jph3rGRCKprnHtGEAUXj7TuISul5ytJCx5V5SKSuXm9yVulgk40T2TAVXOjdVVCnHpA4TbAbvNX+f1IV2hIcmVSZya98zGYGopuOyHCq2QorUaq+pYIbT53WxffmACebFLqNpPZME9bpJhK5VJBj5MRyzkdCRlXLqFOj 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: From: Peter Xu Swap pud entries do not always return true for pud_huge() for all archs. x86 and sparc (so far) allow it, but all the rest do not accept a swap entry to be reported as pud_huge(). So it's not safe to check swap entries within pud_huge(). Check swap entries before pud_huge(), so it should be always safe. This is the only place in the kernel that (IMHO, wrongly) relies on pud_huge() to return true on pud swap entries. The plan is to cleanup pXd_huge() to only report non-swap mappings for all archs. Cc: Alistair Popple Signed-off-by: Peter Xu Reviewed-by: Jason Gunthorpe --- mm/hmm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 277ddcab4947..c44391a0246e 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -424,7 +424,7 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long start, unsigned long end, walk->action = ACTION_CONTINUE; pud = READ_ONCE(*pudp); - if (pud_none(pud)) { + if (pud_none(pud) || !pud_present(pud)) { spin_unlock(ptl); return hmm_vma_walk_hole(start, end, -1, walk); } @@ -435,11 +435,6 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long start, unsigned long end, unsigned long *hmm_pfns; unsigned long cpu_flags; - if (!pud_present(pud)) { - spin_unlock(ptl); - return hmm_vma_walk_hole(start, end, -1, walk); - } - i = (addr - range->start) >> PAGE_SHIFT; npages = (end - addr) >> PAGE_SHIFT; hmm_pfns = &range->hmm_pfns[i];