From patchwork Mon Dec 18 13:58:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ene X-Patchwork-Id: 180440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1258137dyi; Mon, 18 Dec 2023 06:01:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5zhWVVqMOO6dnEjqy4wGAqb08TtcFSZECGJZE01dEm5vvSIwSZZ5kzktdyoSMktkFuWcR X-Received: by 2002:a17:902:ecc5:b0:1d3:bc22:17ba with SMTP id a5-20020a170902ecc500b001d3bc2217bamr816263plh.125.1702908090149; Mon, 18 Dec 2023 06:01:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702908090; cv=none; d=google.com; s=arc-20160816; b=N8KdddHOsCBMyvoc23ohr++aBaoofBYe4FvIXyaV1BQxY09oVtnn1NlfRjsLC4VUiY d/NjeCG/Zkl6qnCIcdNVoClaHBBdzm3/HYXNGBxxTAmGb0Vop7U046PTsL6YUuzkVOjj lUEd80eBTmvUZ1qT0aFmH48rxQ/BAKFz+YBnoLvq4EnJPHpbNb2WETfEh6nBS59js/8X RJvI8kdpQEfQnxsr1g5yVA50FPdKr/5/BBNH0nBiS+Hw2apCdCZCLYa1JIX/8F3/J8rh C1J7E3Unm+V73cus+h953LMcZWeFMTLEMlXcAxRWF0VROZQsndts2t5CPnJTYztSHba1 P4Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=/snQWpLs/9aDAfFwDwLoi7Q0iJhDc3rGT80KePC/RNs=; fh=4RXM1FFjr/2FDx2f50K7N78eRirWaG15JMQkQwGVT00=; b=VPXChjeeIOeuMYkoE5etIrjtVXGzRU2nRYU9dyyr6uUWmzE15cIFlPNU89dVSWy6Ue iHD6KVX9UWkX5y1P5JkN4QhhB3eqYL72XXS9pEjGADqZiZN5gnuieWVw+YzRa+P7ZeiC RQ8Rv3rMs0RRcqwBMNNgP3AnR/6lOnQMhFIEHwNGH+zO3xbqtcRKlmeEf+sJrI8VijJP jBjzIVWbftHge4P67KQn9W/xV+TrjaVyhMoVRS9W/P/BzXQUV0go8KN3FX/XACFo5GJy YMifrNIlBQZrGyRvwetdgL8RBX6nlDmzIKRRwK/Av5kH5lYlWb53zlgO8rQoKDZRgoTm d5FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WPZ7iWSK; spf=pass (google.com: domain of linux-kernel+bounces-3790-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3790-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ix10-20020a170902f80a00b001d3be63dde9si1566061plb.457.2023.12.18.06.01.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 06:01:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3790-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WPZ7iWSK; spf=pass (google.com: domain of linux-kernel+bounces-3790-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3790-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C6728283E19 for ; Mon, 18 Dec 2023 14:01:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DACB94236C; Mon, 18 Dec 2023 14:00:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WPZ7iWSK" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 691413A1AC for ; Mon, 18 Dec 2023 13:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--sebastianene.bounces.google.com Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3335231c733so1378329f8f.0 for ; Mon, 18 Dec 2023 05:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702907995; x=1703512795; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/snQWpLs/9aDAfFwDwLoi7Q0iJhDc3rGT80KePC/RNs=; b=WPZ7iWSKl1JRBaFmrbik+HI9MDrQtPrfCxHSsLNW3sP5Ojjd5v0hICyuupS4XScg8Z iuKMp8JchtduynlhpyGRgRaURWL+0wU3VGMF9xZ2cFES+osl4zD0M0aiICqWjp0fNgnR SX2eO0uLZsbS8ctIqJA8OjKHQpnlsuXh1ZoEoWXQzp7bCP4xbw1aaITnpjfpNKBRppim zlORkhUTIMaBLQbjQ3zio3oZlcGGjA9sdOq5lWNRQCRmV+dHqBoDmcqprH5vFYW1ohpM xrMwqLgRu9vX6C+pnN4nlEFT1Sle+aSEjgES3BQSJxxoA0DQcaLIrFNbY/SUrPJ/gPD2 dNRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702907995; x=1703512795; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/snQWpLs/9aDAfFwDwLoi7Q0iJhDc3rGT80KePC/RNs=; b=WSz/lUgmGRMBavAqfVVLQRi1+hP85MEcZmesNEm0rHsAiViGY3tKdY42fJ6Viaj4GS dE0G120ieVTD1Y2Qs639CWFQxWpf+GTyITrgw6943A/zqa38M1M66yFK4YuQZEJ1EOL+ GaOmYHhzWDXWETd9rd7CDb+6C9WyfXMmkh9MZO2gOHQE58eeqm7+v42SWcc8qvk8Zpjh z22DPhLV/pqvRP6vFhna08Je3iJJdHAxAdxYPYO46p6xBV1R/Q9Wyq9ZT05/0T3YACJ3 5aUzWMunLGZc7swjj6EPw4WcQzk1RG65vtU1E9MWuzSXeXiGJ+wDv5BJ5fT2OU5SrqfQ 6Fpw== X-Gm-Message-State: AOJu0YySMrer4q9zyD0foRrp7LXq9vEcK5/xChJ93vJ0U91b/833m3b6 pPmi8pxhlGeEI41geQA/PjKK81IayTbx8pu7QRs= X-Received: from sebkvm.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:cd5]) (user=sebastianene job=sendgmr) by 2002:adf:f548:0:b0:336:68ff:e929 with SMTP id j8-20020adff548000000b0033668ffe929mr7158wrp.5.1702907995808; Mon, 18 Dec 2023 05:59:55 -0800 (PST) Date: Mon, 18 Dec 2023 13:58:54 +0000 In-Reply-To: <20231218135859.2513568-2-sebastianene@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20231218135859.2513568-2-sebastianene@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231218135859.2513568-6-sebastianene@google.com> Subject: [PATCH v4 04/10] arm64: ptdump: Expose the attribute parsing functionality From: Sebastian Ene To: will@kernel.org, Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , catalin.marinas@arm.com, mark.rutland@arm.com, akpm@linux-foundation.org, maz@kernel.org Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-team@android.com, vdonnefort@google.com, qperret@google.com, smostafa@google.com, Sebastian Ene X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785628553519963528 X-GMAIL-MSGID: 1785628553519963528 To keep the same output format as the arch specific ptdump and for the sake of reusability, move the parser's state tracking code out of the arch specific. Signed-off-by: Sebastian Ene --- arch/arm64/include/asm/ptdump.h | 41 ++++++++++++++++++++++++++++++++- arch/arm64/mm/ptdump.c | 36 ++--------------------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/arch/arm64/include/asm/ptdump.h b/arch/arm64/include/asm/ptdump.h index 581caac52..23510be35 100644 --- a/arch/arm64/include/asm/ptdump.h +++ b/arch/arm64/include/asm/ptdump.h @@ -9,6 +9,8 @@ #include #include +#include + struct addr_marker { unsigned long start_address; @@ -21,15 +23,52 @@ struct ptdump_info { unsigned long base_addr; }; +struct prot_bits { + u64 mask; + u64 val; + const char *set; + const char *clear; +}; + +struct pg_level { + const struct prot_bits *bits; + const char *name; + size_t num; + u64 mask; +}; + +/* + * The page dumper groups page table entries of the same type into a single + * description. It uses pg_state to track the range information while + * iterating over the pte entries. When the continuity is broken it then + * dumps out a description of the range. + */ +struct pg_state { + struct ptdump_state ptdump; + struct seq_file *seq; + const struct addr_marker *marker; + unsigned long start_address; + int level; + u64 current_prot; + bool check_wx; + unsigned long wx_pages; + unsigned long uxn_pages; +}; + void ptdump_walk(struct seq_file *s, struct ptdump_info *info); +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val); #ifdef CONFIG_PTDUMP_DEBUGFS #define EFI_RUNTIME_MAP_END DEFAULT_MAP_WINDOW_64 void __init ptdump_debugfs_register(struct ptdump_info *info, const char *name); #else static inline void ptdump_debugfs_register(struct ptdump_info *info, const char *name) { } -#endif +#endif /* CONFIG_PTDUMP_DEBUGFS */ void ptdump_check_wx(void); +#else +static inline void note_page(void *pt_st, unsigned long addr, + int level, u64 val) { } #endif /* CONFIG_PTDUMP_CORE */ #ifdef CONFIG_DEBUG_WX diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index e305b6593..64127c70b 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -66,31 +66,6 @@ static struct addr_marker address_markers[] = { seq_printf(m, fmt); \ }) -/* - * The page dumper groups page table entries of the same type into a single - * description. It uses pg_state to track the range information while - * iterating over the pte entries. When the continuity is broken it then - * dumps out a description of the range. - */ -struct pg_state { - struct ptdump_state ptdump; - struct seq_file *seq; - const struct addr_marker *marker; - unsigned long start_address; - int level; - u64 current_prot; - bool check_wx; - unsigned long wx_pages; - unsigned long uxn_pages; -}; - -struct prot_bits { - u64 mask; - u64 val; - const char *set; - const char *clear; -}; - static const struct prot_bits pte_bits[] = { { .mask = PTE_VALID, @@ -170,13 +145,6 @@ static const struct prot_bits pte_bits[] = { } }; -struct pg_level { - const struct prot_bits *bits; - const char *name; - size_t num; - u64 mask; -}; - static struct pg_level pg_level[] = { { /* pgd */ .name = "PGD", @@ -248,8 +216,8 @@ static void note_prot_wx(struct pg_state *st, unsigned long addr) st->wx_pages += (addr - st->start_address) / PAGE_SIZE; } -static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, - u64 val) +void note_page(struct ptdump_state *pt_st, unsigned long addr, int level, + u64 val) { struct pg_state *st = container_of(pt_st, struct pg_state, ptdump); static const char units[] = "KMGTPE";