From patchwork Wed Mar 4 03:19:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1248761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48XJyV6P47z9sSG for ; Wed, 4 Mar 2020 14:19:30 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=DYUXhaRa; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48XJyV3zDvzDqRj for ; Wed, 4 Mar 2020 14:19:30 +1100 (AEDT) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48XJyH4dy7zDqSN for ; Wed, 4 Mar 2020 14:19:19 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=DYUXhaRa; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 48XJyH2hpcz9sSR; Wed, 4 Mar 2020 14:19:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1583291959; bh=ZNtuSmXB8hupqUCKpjLjEyppEvdH/orroaxeNivkp5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DYUXhaRaGtsBGicHIphGYrW42oXphaELYBeJQjNRx3TlxStuUGAF2GDgo7D2Q1mmi ppXFjABn6E5wa0K3udcSwMG1AT1HUSW9+2dj49TNjcSixy7iNXXABMHisBacCVg282 x6GYdNPLf3Y80L7Mj6lIUWfVuPmbW9fk19TSZqUIsd4/CKnSV+PX6zpZ9WftG32PKf dn3Jz2Zx/sGmeq4Ot71qMY3WJnnmdQ4MJ9R79GXSPv3VE1HOljATFW4IJVqPVgha/O xagTErsz8KA9V5+V2axJIEXCx//fJsAS+y4UTjooru+ApEicAlVeOy6pafpAdp16GF 3pDm7BK9XljIw== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 4 Mar 2020 14:19:13 +1100 Message-Id: <20200304031913.150094-5-amitay@ozlabs.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200304031913.150094-1-amitay@ozlabs.org> References: <20200304031913.150094-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v3 4/4] libpdbg: Improve the logic to check if fdt is writable X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/device.c | 2 +- libpdbg/dtb.c | 24 +++++++++--------------- libpdbg/target.h | 3 ++- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/libpdbg/device.c b/libpdbg/device.c index cd8a459..604cddb 100644 --- a/libpdbg/device.c +++ b/libpdbg/device.c @@ -355,7 +355,7 @@ bool pdbg_target_set_property(struct pdbg_target *target, const char *name, cons if (!p) return false; - if (!target->fdt || !pdbg_fdt_is_writeable(target->fdt)) + if (!target->fdt || pdbg_fdt_is_readonly(target->fdt)) return false; if (len != size) diff --git a/libpdbg/dtb.c b/libpdbg/dtb.c index 57502c1..35923b0 100644 --- a/libpdbg/dtb.c +++ b/libpdbg/dtb.c @@ -63,10 +63,12 @@ static struct pdbg_dtb pdbg_dtb = { .backend = { .fd = -1, .len = -1, + .readonly = true, }, .system = { .fd = -1, .len = -1, + .readonly = true, }, }; @@ -270,6 +272,7 @@ static void mmap_dtb(char *file, bool readonly, struct pdbg_mfile *mfile) .fd = fd, .len = statbuf.st_size, .fdt = dtb, + .readonly = readonly, }; return; @@ -408,24 +411,15 @@ done: return dtb; } -static bool is_fdt_mapped(void *fdt, struct pdbg_mfile *mfile) +bool pdbg_fdt_is_readonly(void *fdt) { - if (mfile->fdt == fdt && mfile->fd != -1 && mfile->len != -1) { - return true; - } - - return false; -} + if (pdbg_dtb.system.fdt == fdt) + return pdbg_dtb.system.readonly; -bool pdbg_fdt_is_writeable(void *fdt) -{ - bool ok; - - ok = is_fdt_mapped(fdt, &pdbg_dtb.system); - if (!ok) - ok = is_fdt_mapped(fdt, &pdbg_dtb.backend); + if (pdbg_dtb.backend.fdt == fdt) + return pdbg_dtb.backend.readonly; - return ok; + return true; } static void close_dtb(struct pdbg_mfile *mfile) diff --git a/libpdbg/target.h b/libpdbg/target.h index fffdc49..3b74844 100644 --- a/libpdbg/target.h +++ b/libpdbg/target.h @@ -60,6 +60,7 @@ struct pdbg_mfile { int fd; ssize_t len; void *fdt; + bool readonly; }; struct pdbg_dtb { @@ -80,7 +81,7 @@ extern struct list_head target_classes; struct pdbg_dtb *pdbg_default_dtb(void *system_fdt); const char *pdbg_get_backend_option(void); -bool pdbg_fdt_is_writeable(void *fdt); +bool pdbg_fdt_is_readonly(void *fdt); struct chipop *pib_to_chipop(struct pdbg_target *target); bool target_is_virtual(struct pdbg_target *target);