From patchwork Tue Mar 5 04:37:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13581599 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 A7068C5478C for ; Tue, 5 Mar 2024 04:38:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C0A194000B; Mon, 4 Mar 2024 23:38:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 37097940007; Mon, 4 Mar 2024 23:38:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2389094000B; Mon, 4 Mar 2024 23:38:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 13878940007 for ; Mon, 4 Mar 2024 23:38:56 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E21E6A10F6 for ; Tue, 5 Mar 2024 04:38:55 +0000 (UTC) X-FDA: 81861730230.04.A5A92BD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 6352540013 for ; Tue, 5 Mar 2024 04:38:54 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hGLzM8g1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.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=1709613534; 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=+OBCTz9lvlJv+Cv6bxuJooI+JmxCAuhU7weo02f7lPE=; b=omFw9pLv696CgJWqL6YM6RbImQixG/448pYpa3hpWnPduPPDTUwDOT9uNtw/oARQ6A3W+D uK3Uw/WgM6G1fQdeua3G99YijJYG83SHslYMbBkId6IPcPeh+lgxc3Kca4RGVs5wynWQIZ OyHOd4tA6Tsen8jL+D9KW3Q3pPSSCvs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hGLzM8g1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.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=1709613534; a=rsa-sha256; cv=none; b=yMAlArPFi1YHpzcX0dPnQtLe45gMMGcybN2e8laPjZdgDq+r7G9gjxeaRqUgN/13mM9XL8 kuMVxgO3mISFfc2ZlrQvKUTchDZ/RQI+wod8rO6QcpGxHQ/sY/jldae1voTn63OuODvxcY fmKoffG5JCCnUjXYo4BhuncZISilW20= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709613533; 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=+OBCTz9lvlJv+Cv6bxuJooI+JmxCAuhU7weo02f7lPE=; b=hGLzM8g1Vt6x5kSEs8obROHOr0jOpbDyHdUHRmmeVa+yS0s344VpCAZwwz+MO+MRJyXd3R B3VdJelFpiZVlHGGlwNMDgYI4DZejqaKc/hXZo2GJUbyc6yP1XACo5NKIpsINbXHa/a+Di oryfqmnkqkZka7blet3Yy/z5iF032NI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-mm-VBS-RM56uWvAAq4EvGA-1; Mon, 04 Mar 2024 23:38:48 -0500 X-MC-Unique: mm-VBS-RM56uWvAAq4EvGA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 31F86101A5BB; Tue, 5 Mar 2024 04:38:47 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52DABC1F086; Tue, 5 Mar 2024 04:38:39 +0000 (UTC) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Christophe Leroy , x86@kernel.org, "Kirill A . Shutemov" , Jason Gunthorpe , Yang Shi , peterx@redhat.com, Andrew Morton , linuxppc-dev@lists.ozlabs.org, Muchun Song , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com Subject: [PATCH v3 06/10] mm/kasan: Use pXd_leaf() in shadow_mapped() Date: Tue, 5 Mar 2024 12:37:46 +0800 Message-ID: <20240305043750.93762-7-peterx@redhat.com> In-Reply-To: <20240305043750.93762-1-peterx@redhat.com> References: <20240305043750.93762-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspamd-Queue-Id: 6352540013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: m35xtdmr4jbm6qwncsaz1dxkjzx8dkhb X-HE-Tag: 1709613534-507373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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 There is an old trick in shadow_mapped() to use pXd_bad() to detect huge pages. After commit 93fab1b22ef7 ("mm: add generic p?d_leaf() macros") we have a global API for huge mappings. Use that to replace the trick. Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Dmitry Vyukov Cc: Vincenzo Frascino Cc: kasan-dev@googlegroups.com Signed-off-by: Peter Xu Reviewed-by: Mike Rapoport (IBM) --- mm/kasan/shadow.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 9ef84f31833f..d6210ca48dda 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -199,19 +199,12 @@ static bool shadow_mapped(unsigned long addr) pud = pud_offset(p4d, addr); if (pud_none(*pud)) return false; - - /* - * We can't use pud_large() or pud_huge(), the first one is - * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse - * pud_bad(), if pud is bad then it's bad because it's huge. - */ - if (pud_bad(*pud)) + if (pud_leaf(*pud)) return true; pmd = pmd_offset(pud, addr); if (pmd_none(*pmd)) return false; - - if (pmd_bad(*pmd)) + if (pmd_leaf(*pmd)) return true; pte = pte_offset_kernel(pmd, addr); return !pte_none(ptep_get(pte));