From nobody Fri Dec 19 20:34:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1601038668; cv=none; d=zohomail.com; s=zohoarc; b=ZIanqCxgjQvKnWPuYVdxiZZfeEzvk+fvGaOidkkrKrf4gKpgaX1raeqgzJDuQhRbcMk9/EQSOgG+yte/S5QStucPsbaV6dU0DbbV1s2vZN7eg+3A8JS30JfMvcVg+wjuMRR/QK00BCz9mPPQwO0WEFIINqz++lh9xnibhQggAwA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038668; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9eI5ySrz2OiQLFHfiZ2ocnjA2ayiRqTZ1gQtwjJhv6Q=; b=InQFBHQFD0wWb5EMCVNmQ1qV4LKCXWEs+KshDstejQDj+YOqghhXAJ9UC2Tjv7hvpHByv22Ebfr1k/QaF8KBs8LWE99cMOqfTAC+NLNS656B86Jv3m/BO5cS7iu6WTFWaoA7Kz3jNehXqXJaQXswvIpHesQSlBzOY7WLfuC6o5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160103866862172.93139122296895; Fri, 25 Sep 2020 05:57:48 -0700 (PDT) Received: from localhost ([::1]:54766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnIJ-0007Xc-9z for importer@patchew.org; Fri, 25 Sep 2020 08:57:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCt-0007pi-Uo for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:11 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46531) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCr-0001Qz-4I for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:11 -0400 Received: by mail-wr1-x441.google.com with SMTP id o5so3429359wrn.13 for ; Fri, 25 Sep 2020 05:52:08 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id v9sm3129761wrv.35.2020.09.25.05.51.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:52:00 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 41FCB1FF9A; Fri, 25 Sep 2020 13:51:49 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9eI5ySrz2OiQLFHfiZ2ocnjA2ayiRqTZ1gQtwjJhv6Q=; b=eb6ALVdnmFHCTlliFN8w9QQPFweSJ6Di6etcFIdumY21j+3VWYHbhdRz7orrZd4HNW BC4nCBlDbhKhp6XnTOh2XkBcX/rpHXp3DeYZ34PeLz4kqPPrY/F5SNXgz7NrQCyoBNGy KNB1ehCec9b7w+DJrxTUXT2jfRP2isSynh5wWCGH7z+PirCFWe6mkr56BuMx3N/o4LaE PNOprC+3WFDvrcMxerUHXbCs0Sb7JsONYWNzLbecNDWZuHuTaveLGuI7HmFLAXC2FOxF DmT1faygi6/tecLZE2OKcL89BFE2X2kCsFiu3TRkNllSt59innjb3U6sG8Sy3jpE5FZQ EulQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9eI5ySrz2OiQLFHfiZ2ocnjA2ayiRqTZ1gQtwjJhv6Q=; b=TMPCoS0OgteJYyAYWLS+7UFF53dCZtLqLcFrUOhcwV2k122KefkRrT7vJsPdCamrMc TXV+DXAe49CfXu7p9KQCoUC5d4pjIJ+OWyvkaF3R9+wMNwwxBaeq0J8MlX3CcTtwHzjs PgQyVBNSwxPr+Qwr37bcEa9GOY3Hmal3j37VJVNjHdOilUvQqYAVmQeStdKcjRstXKY1 Ua22fDu8uKg7bT5brlW2RpiZz4oTXVrHArjJtF6h89Am9GM55vHw/Zk6nHS7TGQ5HLXI 2Jnvz23pxzW0vq6AiEH/CCz3sLVavSfo8n2ZVJAIfZQr4X5XV55tWlVVddmrARFACqbn 3qpg== X-Gm-Message-State: AOAM533yKkaNHs3KkwhHmY9jQQrjP/9VAakezPY2OKPp7XLVmFqTDTkb ysvZj7+XVewOm2bH4V1k2Uzmtw== X-Google-Smtp-Source: ABdhPJwrBoyZaa9ySYnxA8u48SmELYctXq1T0Fdj46EQTS15QzgJZGB+uHCKPTfkdtsZGNMxEX84TA== X-Received: by 2002:a05:6000:7:: with SMTP id h7mr4620923wrx.16.1601038327710; Fri, 25 Sep 2020 05:52:07 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org, maxim.uvarov@linaro.org, joakim.bech@linaro.org, ilias.apalodimas@linaro.org, tomas.winkler@intel.com, yang.huang@intel.com, bing.zhu@intel.com, Matti.Moell@opensynergy.com, hmo@opensynergy.com Subject: [RFC PATCH 11/19] tools/vhost-user-rpmb: add --flash-path for backing store Date: Fri, 25 Sep 2020 13:51:39 +0100 Message-Id: <20200925125147.26943-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200925125147.26943-1-alex.bennee@linaro.org> References: <20200925125147.26943-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, takahiro.akashi@linaro.org, virtualization@lists.linuxfoundation.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , arnd@linaro.org, stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We will need to store the data somewhere so add the option to point to the file where we will keep the data. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 58 +++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 7b3b29ccfc5b..64bd7e79f573 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -13,9 +13,15 @@ #include #include #include +#include #include #include #include +#include +#include +#include +#include +#include =20 #include "contrib/libvhost-user/libvhost-user-glib.h" #include "contrib/libvhost-user/libvhost-user.h" @@ -27,6 +33,7 @@ #endif =20 static gchar *socket_path; +static char *flash_path; static gint socket_fd =3D -1; static gboolean print_cap; static gboolean verbose; @@ -35,6 +42,7 @@ static gboolean debug; static GOptionEntry options[] =3D { { "socket-path", 0, 0, G_OPTION_ARG_FILENAME, &socket_path, "Location = of vhost-user Unix domain socket, incompatible with --fd", "PATH" }, + { "flash-path", 0, 0, G_OPTION_ARG_FILENAME, &flash_path, "Location of= raw flash image file", "PATH" }, { "fd", 0, 0, G_OPTION_ARG_INT, &socket_fd, "Specify the file-descript= or of the backend, incompatible with --socket-path", "FD" }, { "print-capabilities", 0, 0, G_OPTION_ARG_NONE, &print_cap, "Output t= o stdout the backend capabilities in JSON format and exit", NULL}, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be more verbose in = output", NULL}, @@ -47,6 +55,8 @@ enum { }; =20 /* These structures are defined in the specification */ +#define KiB (1UL << 10) +#define MAX_RPMB_SIZE (KiB * 128 * 256) =20 struct virtio_rpmb_config { uint8_t capacity; @@ -75,6 +85,8 @@ typedef struct VuRpmb { VugDev dev; struct virtio_rpmb_config virtio_config; GMainLoop *loop; + int flash_fd; + void *flash_map; } VuRpmb; =20 struct virtio_rpmb_ctrl_command { @@ -116,6 +128,8 @@ vrpmb_get_config(VuDev *dev, uint8_t *config, uint32_t = len) VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); g_return_val_if_fail(len <=3D sizeof(struct virtio_rpmb_config), -1); memcpy(config, &r->virtio_config, len); + + g_info("%s: done", __func__); return 0; } =20 @@ -192,6 +206,41 @@ static const VuDevIface vuiface =3D { .set_config =3D vrpmb_set_config, }; =20 +static bool vrpmb_load_flash_image(VuRpmb *r, char *img_path) +{ + GStatBuf statbuf; + size_t map_size; + + if (g_stat(img_path, &statbuf) < 0) { + g_error("couldn't stat %s", img_path); + return false; + } + + r->flash_fd =3D g_open(img_path, O_RDWR, 0); + if (r->flash_fd < 0) { + g_error("couldn't open %s (%s)", img_path, strerror(errno)); + return false; + } + + if (statbuf.st_size > MAX_RPMB_SIZE) { + g_warning("%s larger than maximum size supported", img_path); + map_size =3D MAX_RPMB_SIZE; + } else { + map_size =3D statbuf.st_size; + } + r->virtio_config.capacity =3D map_size / (128 *KiB); + r->virtio_config.max_wr_cnt =3D 1; + r->virtio_config.max_rd_cnt =3D 1; + + r->flash_map =3D mmap(NULL, map_size, PROT_READ, MAP_SHARED, r->flash_= fd, 0); + if (r->flash_map =3D=3D MAP_FAILED) { + g_error("failed to mmap file"); + return false; + } + + return true; +} + static void vrpmb_destroy(VuRpmb *r) { vug_deinit(&r->dev); @@ -216,7 +265,7 @@ static gboolean hangup(gpointer user_data) return true; } =20 -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { GError *error =3D NULL; GOptionContext *context; @@ -236,6 +285,13 @@ int main (int argc, char *argv[]) exit(0); } =20 + if (!flash_path || !g_file_test(flash_path, G_FILE_TEST_EXISTS)) { + g_printerr("Please specify a valid --flash-path for the flash imag= e\n"); + exit(EXIT_FAILURE); + } else { + vrpmb_load_flash_image(&rpmb, flash_path); + } + if (!socket_path && socket_fd < 0) { g_printerr("Please specify either --fd or --socket-path\n"); exit(EXIT_FAILURE); --=20 2.20.1