Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp112028rdh; Mon, 18 Dec 2023 06:00:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhqzGjt+xR1v10tNIGoG2rCUFaiRCHTEgYGUIQU1/47e3R+OgreiMp19NpNlL4yBNKsUVf X-Received: by 2002:a05:6808:3a0d:b0:3b9:dbc5:2fe8 with SMTP id gr13-20020a0568083a0d00b003b9dbc52fe8mr24652234oib.47.1702908057890; Mon, 18 Dec 2023 06:00:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702908057; cv=none; d=google.com; s=arc-20160816; b=ayD680tO+iNFUajdXCgve1ilhgL2NOdR+ewDoax+zxT1/Vw46NG7Sg9xS31550YJ0Z OBaRM6p0ucYhr4OGPJMXeO9fMj+7lTLx+E2uW0wkRHBcrzUXSRLN4lQQyVLoqMht/LqS 1AAb2MFJvU2wu9eRR6aRDF+PRw682fMu5aHnF0qiAoGt9TZjOBo5INzVqC0p+lWNykJ5 tqW6pH2sCSoH1NWZowHw+2xaq9408YF5OKTDwzfHhaNZfParENBgE0jP5eNbjGWNFrK4 y1CVBN8W+k6thM7Wfvrq4+4K6TDnZYvykzE2Cx4XYLTrgE0YWuyFO4HnUgPEMvqgiR/2 ue8Q== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3790-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r20-20020a0ce294000000b0067f584b65besi45649qvl.263.2023.12.18.06.00.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 06:00:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3790-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3790-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 928331C246CC for ; Mon, 18 Dec 2023 14:00:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D62033D540; Mon, 18 Dec 2023 13:59:59 +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 Content-Type: text/plain; charset="UTF-8" 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"; -- 2.43.0.472.g3155946c3a-goog