From patchwork Tue Oct 18 22:01:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9383193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D437607D0 for ; Tue, 18 Oct 2016 22:03:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A53929792 for ; Tue, 18 Oct 2016 22:03:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C464297E4; Tue, 18 Oct 2016 22:03:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B155E2977C for ; Tue, 18 Oct 2016 22:03:48 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwcSx-0003Ep-I7; Tue, 18 Oct 2016 22:02:35 +0000 Received: from mail-it0-f41.google.com ([209.85.214.41]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bwcSR-0002mw-Q7 for linux-arm-kernel@lists.infradead.org; Tue, 18 Oct 2016 22:02:05 +0000 Received: by mail-it0-f41.google.com with SMTP id k64so23323334itb.0 for ; Tue, 18 Oct 2016 15:01:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zBPjO3Q0WxtNTEQ6Gt7f2HlFEJxUh+qV7S6apd8w3Ps=; b=cXpnA2d8gIgKIdwXOif/bSUAVdi4m+59dFYjx3eQ+ZNFpaMLxnVPDDnlvF7MVLpqgb aivLYlTNH+x8LNUce4gBJxZt8Bm2CH5wKW3MLKCkZfbtQWDfNIPbB9iotlBNpWHO4wut hv4XMU/FjFOahaifb9nyqZDo+ansn0B5nfAZ4pLIiGy6myr+sG6m2d96VCusIDLU1g2l RXp/mx4B+sIj1yikYuQPwmfrGxww2r4fe81+eWLtPHpS/t0DtSpcuf7mfaz+B9qpV3sa dKGc07Nrrbk19yoBddiZoMPe4gAmGh9AroV5txq1q2MARLub/LmzuIroELILw7SqhOl4 bWmA== X-Gm-Message-State: AA6/9RkFizV0QOeMq8Ma4exrGjNgY8y+C+sQTkjSZbGDDd3LF5yvGmnOZeuJojpEnvdHO67v X-Received: by 10.36.112.199 with SMTP id f190mr17511605itc.60.1476828102825; Tue, 18 Oct 2016 15:01:42 -0700 (PDT) Received: from labbott-redhat-machine.redhat.com ([2601:602:9800:177f::2946]) by smtp.gmail.com with ESMTPSA id f14sm2157970ita.10.2016.10.18.15.01.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2016 15:01:41 -0700 (PDT) From: Laura Abbott To: AKASHI Takahiro , Mark Rutland , Ard Biesheuvel , David Brown , Will Deacon , Catalin Marinas Subject: [PATCHv3 2/4] arm64: dump: Make the page table dumping seq_file optional Date: Tue, 18 Oct 2016 15:01:29 -0700 Message-Id: <1476828091-17802-3-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476828091-17802-1-git-send-email-labbott@redhat.com> References: <1476828091-17802-1-git-send-email-labbott@redhat.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161018_150203_929089_CD2F0488 X-CRM114-Status: GOOD ( 13.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, Kees Cook , kernel-hardening@lists.openwall.com, Matt Fleming , linux-kernel@vger.kernel.org, Laura Abbott , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The page table dumping code always assumes it will be dumping to a seq_file to userspace. Future code will be taking advantage of the page table dumping code but will not need the seq_file. Make the seq_file optional for these cases. Reviewed-by: Kees Cook Reviewed-by: Mark Rutland Tested-by: Mark Rutland Acked-by: Mark Rutland Signed-off-by: Laura Abbott --- v3: No changes --- arch/arm64/mm/dump.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c index f0f0be7..bb36649 100644 --- a/arch/arm64/mm/dump.c +++ b/arch/arm64/mm/dump.c @@ -50,6 +50,18 @@ static const struct addr_marker address_markers[] = { { -1, NULL }, }; +#define pt_dump_seq_printf(m, fmt, args...) \ +({ \ + if (m) \ + seq_printf(m, fmt, ##args); \ +}) + +#define pt_dump_seq_puts(m, fmt) \ +({ \ + if (m) \ + 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 @@ -186,7 +198,7 @@ static void dump_prot(struct pg_state *st, const struct prot_bits *bits, s = bits->clear; if (s) - seq_printf(st->seq, " %s", s); + pt_dump_seq_printf(st->seq, " %s", s); } } @@ -200,14 +212,14 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, st->level = level; st->current_prot = prot; st->start_address = addr; - seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); + pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } else if (prot != st->current_prot || level != st->level || addr >= st->marker[1].start_address) { const char *unit = units; unsigned long delta; if (st->current_prot) { - seq_printf(st->seq, "0x%016lx-0x%016lx ", + pt_dump_seq_printf(st->seq, "0x%016lx-0x%016lx ", st->start_address, addr); delta = (addr - st->start_address) >> 10; @@ -215,17 +227,17 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, delta >>= 10; unit++; } - seq_printf(st->seq, "%9lu%c %s", delta, *unit, + pt_dump_seq_printf(st->seq, "%9lu%c %s", delta, *unit, pg_level[st->level].name); if (pg_level[st->level].bits) dump_prot(st, pg_level[st->level].bits, pg_level[st->level].num); - seq_puts(st->seq, "\n"); + pt_dump_seq_puts(st->seq, "\n"); } if (addr >= st->marker[1].start_address) { st->marker++; - seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); + pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } st->start_address = addr; @@ -235,7 +247,7 @@ static void note_page(struct pg_state *st, unsigned long addr, unsigned level, if (addr >= st->marker[1].start_address) { st->marker++; - seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); + pt_dump_seq_printf(st->seq, "---[ %s ]---\n", st->marker->name); } }