From nobody Thu Apr 25 14:33:28 2024 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=1601038410; cv=none; d=zohomail.com; s=zohoarc; b=mM+FrdiWamKr8/b0XdV/diE+P5D6zbmjLCicmmuz1HM35pJ793JMqew9bpzszFcFWcgT/jKPnTD9E/cCTKjDBd4VoIUuOIf+KrHFixor/f3H+WjKYT7duICXG9RsDjuL9QzPlF8uCjLVsRTmeQ88xKt211MNMoqONWHIfEvAMIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038410; 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=eP8IRx33KYKqoe6PrhN3NXzNGwmBRsBzrSybQmnNqbM=; b=fsdm4nChum5pRl79DKcCKWGFYXaIVDq6g9/XjjoI/2+r0SMWXbhxURV8HMTMpL8ff9L3YearSMy5tc7RYJ9HCRjRixLouGQ7e7gVzph0y9+fuFx4qSUMQ1unHEuho0BjgsC5fYlGdEx0g024NzZVhUrqUkUTYaNhHDq9qbsCHOE= 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 1601038410362414.3488880836228; Fri, 25 Sep 2020 05:53:30 -0700 (PDT) Received: from localhost ([::1]:38088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnE8-0000gR-W1 for importer@patchew.org; Fri, 25 Sep 2020 08:53:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCd-0007Nh-I9 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:51:55 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:52801) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCa-0001NU-MH for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:51:55 -0400 Received: by mail-wm1-x342.google.com with SMTP id q9so2946719wmj.2 for ; Fri, 25 Sep 2020 05:51:52 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u66sm2766046wme.12.2020.09.25.05.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:48 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1DD701FF87; Fri, 25 Sep 2020 13:51:48 +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=eP8IRx33KYKqoe6PrhN3NXzNGwmBRsBzrSybQmnNqbM=; b=DFsHI2WrX2bvmPvaYzx4q3vrYDT3aD10kqia+n0n0cLkhAIQvGH7BcatBmpMUgdH5Z tHtEcmi5oA67VPWMPu+54In/VSaVz3SExTkDelbfjLCOL4rkSQdwVk7sMi4aTToGZCWn YJqrYzAJpGoLzHrmExztamoCKN8ljmDo4w4secV3sIhM7L9BTvQi+qm9lWxgFdUfWTdk gThM7iCy2G4HkIC6i+xJsT1NPFpiS/w6kdTjUM5Bh+gVEK4SDZVZtP9gfpZOMDL8JxQl 1AlTzKKoQJaJIZvWTfe/QS4t3+d15isKpHamSbCggX+cCvCh9nx3803zr+eyrSa/f+/H wphw== 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=eP8IRx33KYKqoe6PrhN3NXzNGwmBRsBzrSybQmnNqbM=; b=OAx8MklhcIF/owXvDIEaWhNZabuWXPlOWAI09Iz1w9rA3wG1fOa3uIhxnUJSimURI6 Mz5AXlQ7zKcA0K1wW7DG70wGbgCiibzArEOFj72xrSKwL9fJTdybd1KjHPNFwqvcPzFz xU5O8LVSohwA+NLoRjKZ/WbXjsFYE29eRAiLU+S3xTLPWYpCimjrSD5fKQI0cXJcxij6 SYDBAngL6j21MUpPD+JntuOh5jwIYQ7qD1soFx1eCME941kkVYGyW93msqAZ6iEQdVgM kW7IHly3y2Xxu2fjInSFJb3lKGx+uKQBYt9UV1+/iBcbcQBxGZs0kxbOPilrjKEG4w0q Zh7w== X-Gm-Message-State: AOAM5307eh3c5xLaSaIjqJnwMIriHwOjjrkDvUEEXQKWIFv2YE0RqZgF XUc9UJ2RCgSen/AclhWvOSYKCw== X-Google-Smtp-Source: ABdhPJzqvbmnlt8MESPNUh64kjEJicRNegOyt85mThr8I355eHjzgmjl6Y8OMw0PQM5x3EQSbbn+HQ== X-Received: by 2002:a1c:4e08:: with SMTP id g8mr2952305wmh.53.1601038311085; Fri, 25 Sep 2020 05:51:51 -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 01/19] tools/virtiofsd: add support for --socket-group Date: Fri, 25 Sep 2020 13:51:29 +0100 Message-Id: <20200925125147.26943-2-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::342; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x342.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, "Dr. David Alan Gilbert" , takahiro.akashi@linaro.org, Stefan Hajnoczi , 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) If you like running QEMU as a normal user (very common for TCG runs) but you have to run virtiofsd as a root user you run into connection problems. Adding support for an optional --socket-group allows the users to keep using the command line. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Stefan Hajnoczi --- v1 - tweak documentation and commentary --- docs/tools/virtiofsd.rst | 4 ++++ tools/virtiofsd/fuse_i.h | 1 + tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ tools/virtiofsd/fuse_virtio.c | 20 ++++++++++++++++++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/tools/virtiofsd.rst b/docs/tools/virtiofsd.rst index e33c81ed41f1..085f9b12a6a3 100644 --- a/docs/tools/virtiofsd.rst +++ b/docs/tools/virtiofsd.rst @@ -87,6 +87,10 @@ Options =20 Listen on vhost-user UNIX domain socket at PATH. =20 +.. option:: --socket-group=3DGROUP + + Set the vhost-user UNIX domain socket gid to GROUP. + .. option:: --fd=3DFDNUM =20 Accept connections from vhost-user UNIX domain socket file descriptor FD= NUM. diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h index 1240828208ab..492e002181e2 100644 --- a/tools/virtiofsd/fuse_i.h +++ b/tools/virtiofsd/fuse_i.h @@ -68,6 +68,7 @@ struct fuse_session { size_t bufsize; int error; char *vu_socket_path; + char *vu_socket_group; int vu_listen_fd; int vu_socketfd; struct fv_VuDev *virtio_dev; diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowleve= l.c index 2dd36ec03b6e..4d1ba2925d1b 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -2523,6 +2523,7 @@ static const struct fuse_opt fuse_ll_opts[] =3D { LL_OPTION("--debug", debug, 1), LL_OPTION("allow_root", deny_others, 1), LL_OPTION("--socket-path=3D%s", vu_socket_path, 0), + LL_OPTION("--socket-group=3D%s", vu_socket_group, 0), LL_OPTION("--fd=3D%d", vu_listen_fd, 0), LL_OPTION("--thread-pool-size=3D%d", thread_pool_size, 0), FUSE_OPT_END @@ -2630,6 +2631,11 @@ struct fuse_session *fuse_session_new(struct fuse_ar= gs *args, "fuse: --socket-path and --fd cannot be given together\n"= ); goto out4; } + if (se->vu_socket_group && !se->vu_socket_path) { + fuse_log(FUSE_LOG_ERR, + "fuse: --socket-group can only be used with --socket-path= \n"); + goto out4; + } =20 se->bufsize =3D FUSE_MAX_MAX_PAGES * getpagesize() + FUSE_BUFFER_HEADE= R_SIZE; =20 diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 9e5537506c16..7942d3d11a87 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include =20 #include "contrib/libvhost-user/libvhost-user.h" @@ -924,15 +926,29 @@ static int fv_create_listen_socket(struct fuse_sessio= n *se) =20 /* * Unfortunately bind doesn't let you set the mask on the socket, - * so set umask to 077 and restore it later. + * so set umask appropriately and restore it later. */ - old_umask =3D umask(0077); + if (se->vu_socket_group) { + old_umask =3D umask(S_IROTH | S_IWOTH | S_IXOTH); + } else { + old_umask =3D umask(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOT= H | S_IXOTH); + } if (bind(listen_sock, (struct sockaddr *)&un, addr_len) =3D=3D -1) { fuse_log(FUSE_LOG_ERR, "vhost socket bind: %m\n"); close(listen_sock); umask(old_umask); return -1; } + if (se->vu_socket_group) { + struct group *g =3D getgrnam(se->vu_socket_group); + if (g) { + if (!chown(se->vu_socket_path, -1, g->gr_gid)) { + fuse_log(FUSE_LOG_WARNING, + "vhost socket failed to set group to %s (%d)\n", + se->vu_socket_group, g->gr_gid); + } + } + } umask(old_umask); =20 if (listen(listen_sock, 1) =3D=3D -1) { --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038417; cv=none; d=zohomail.com; s=zohoarc; b=KnF9Q38wusT4QBgJfueiFKsaqIQWrJeKGQ9YCsfPNoExOqRtD0mf7PGq58C7PhNxzMwBktEyHPhAoou9Y1k5TAWDapadyd+rc/209jkg/2AGbKt4y+quyn3506hWH6HNsJO1Jonbs7t4pkQjlo9SvauFYM0lxOD/wU789I8/V9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038417; 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=SXamygjWRu+l2cZVRdgzhVlVjHli46731VVAeJxcnj0=; b=hKZcgqkHTE8G7MEFEHfPMQ/Rtli/BuzTRTBuVLqzy5risCgbxQ9Y/aDufY2SRcR4HhQWehd8Q3qNrUdBwRi+i7EeaZ4NggqHpLA0hPJfxeZwisoxNmRVSBJu7Wz+xtzA471ltcr3UbPyCdJpq18C4GzI0cVZqfugOohfAU+Jwao= 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 160103841747448.71220030771474; Fri, 25 Sep 2020 05:53:37 -0700 (PDT) Received: from localhost ([::1]:38442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnEG-0000ov-50 for importer@patchew.org; Fri, 25 Sep 2020 08:53:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCh-0007To-7D for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:51:59 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:42257) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCd-0001Nd-T8 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:51:58 -0400 Received: by mail-wr1-x444.google.com with SMTP id c18so3461981wrm.9 for ; Fri, 25 Sep 2020 05:51:55 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l8sm2824058wrx.22.2020.09.25.05.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:51 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3B77E1FF8C; Fri, 25 Sep 2020 13:51:48 +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=SXamygjWRu+l2cZVRdgzhVlVjHli46731VVAeJxcnj0=; b=BTf4LrGC9ShJaCd7QstOeBSBNWgniJTYtz1S2uQLBtp8p96nZ8yyrTc3K9Mv8H+dsF fLZOMH/bftpHSJUzvmqHbYrkWOdqVHGcGOGD7exgel5zuNfjs5Va+GZUYNZlM+WoV44i 9EZmKkmmGQ4AXw4IgiDpmILiu97i4YJntdFmugh6Q4EZy1qt3bZMupOTjc9eeWNRaAB5 yQUwUsXOcOrCAKVIQbmi9A5rw4qwRZMR/EXrN/DuoVE2et5lUQ5S0AHBmJjDQY4rro41 bOYVP7RsPDfumygm2CtYUvh1AvRML0We4EuWc2RJfar3kFgD5a3WFy6tuMvhNhfdXkpu 7SBw== 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=SXamygjWRu+l2cZVRdgzhVlVjHli46731VVAeJxcnj0=; b=YfAKra0t5HvkXaMFSrxo/AFZNmBH7Vz+CRNrSa44ONrHfSFaNzlFm+1R2FSvpo5VYK 9GKpLm01mFPwFE2CEP8ngT3KsXWClJWud7YUg+dp8eJuNzfBRWPH7s3EMsBAIy7zDqrH 9+smTLLRkWikouZWEqau60wEPf7L8VC0S9WuGT/FLLXIfwuPqcKqw3oW03EmxIB3nvZG xigl8JL2sxoQC5jjYCIPGLt26fQqGs4I1bn09RXp8Pd77FzSrwiLDkoQJC2Owhz1kKAX nuX/OwVs0sehQ/AJlcp+wj9YeMcxfQe3EtJ8ViRRPTlDYj+N/qlXF2lTNoEPr3/bn38p NiBg== X-Gm-Message-State: AOAM532Qsecl1SQg8l295mg1lmyr988KN/hk7he4chp+L9bfdW0QqsXW D2UTBed6GT2R7PjeQLpy3+9MMw== X-Google-Smtp-Source: ABdhPJwnOxu2IQfb6cc1OdcOPru6ncPuuxtb29c7/Pyq9H42tHlZUVqhjlVWgrmvZyT+1FxRN3Az7A== X-Received: by 2002:adf:df87:: with SMTP id z7mr4469108wrl.239.1601038314313; Fri, 25 Sep 2020 05:51:54 -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 02/19] hw/block: add boilerplate for vhost-user-rpmb device Date: Fri, 25 Sep 2020 13:51:30 +0100 Message-Id: <20200925125147.26943-3-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::444; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x444.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=unavailable 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: Kevin Wolf , jean-philippe@linaro.org, "open list:Block layer core" , "Michael S. Tsirkin" , Max Reitz , 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) This creates the QEMU side of the vhost-user-rpmb device which connects to the remote daemon. It is based of the reasonably modern vhost-user-fs code with bits from vhost-user-blk as we want the virtio-config itself to be sourced from the daemon. Signed-off-by: Alex Benn=C3=A9e --- include/hw/virtio/vhost-user-rpmb.h | 46 ++++ hw/block/vhost-user-rpmb.c | 333 ++++++++++++++++++++++++++++ hw/block/Kconfig | 5 + hw/block/meson.build | 1 + 4 files changed, 385 insertions(+) create mode 100644 include/hw/virtio/vhost-user-rpmb.h create mode 100644 hw/block/vhost-user-rpmb.c diff --git a/include/hw/virtio/vhost-user-rpmb.h b/include/hw/virtio/vhost-= user-rpmb.h new file mode 100644 index 000000000000..7e5988127dc2 --- /dev/null +++ b/include/hw/virtio/vhost-user-rpmb.h @@ -0,0 +1,46 @@ +/* + * vhost-user-rpmb virtio device + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef _VHOST_USER_RPMB_H_ +#define _VHOST_USER_RPMB_H_ + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_USER_RPMB "vhost-user-rpmb-device" +#define VHOST_USER_RPMB(obj) \ + OBJECT_CHECK(VHostUserRPMB, (obj), TYPE_VHOST_USER_RPMB) + +/* This is defined in the VIRTIO spec */ +struct virtio_rpmb_config { + uint8_t capacity; + uint8_t max_wr_cnt; + uint8_t max_rd_cnt; +}; + +typedef struct { + CharBackend chardev; + struct virtio_rpmb_config config; +} VHostUserRPMBConf; + +typedef struct { + /*< private >*/ + VirtIODevice parent; + VHostUserRPMBConf conf; + struct vhost_virtqueue *vhost_vq; + struct vhost_dev vhost_dev; + VhostUserState vhost_user; + VirtQueue *req_vq; + bool connected; + /*< public >*/ +} VHostUserRPMB; + + +#endif /* _VHOST_USER_RPMB_H_ */ diff --git a/hw/block/vhost-user-rpmb.c b/hw/block/vhost-user-rpmb.c new file mode 100644 index 000000000000..de243e7a53a0 --- /dev/null +++ b/hw/block/vhost-user-rpmb.c @@ -0,0 +1,333 @@ +/* + * Vhost-user RPMB virtio device + * + * This is the boilerplate for instantiating a vhost-user device + * implementing a Replay Protected Memory Block (RPMB) device. This is + * a type of flash chip that is protected from replay attacks and used + * for tamper resistant storage. The actual back-end for this driver + * is the vhost-user-rpmb daemon. The code here just connects up the + * device in QEMU and allows it to be instantiated. + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio-bus.h" +#include "hw/virtio/vhost-user-rpmb.h" +#include "qemu/error-report.h" + +/* currently there is no RPMB driver in Linux */ +#define VIRTIO_ID_RPMB 28 /* virtio RPMB */ + +static void vurpmb_get_config(VirtIODevice *vdev, uint8_t *config) +{ + /* this somehow needs to come from the vhost-user daemon */ +} + +static void vurpmb_start(VirtIODevice *vdev) +{ + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + int i; + + if (!k->set_guest_notifiers) { + error_report("binding does not support guest notifiers"); + return; + } + + ret =3D vhost_dev_enable_notifiers(&rpmb->vhost_dev, vdev); + if (ret < 0) { + error_report("Error enabling host notifiers: %d", -ret); + return; + } + + ret =3D k->set_guest_notifiers(qbus->parent, rpmb->vhost_dev.nvqs, tru= e); + if (ret < 0) { + error_report("Error binding guest notifier: %d", -ret); + goto err_host_notifiers; + } + + rpmb->vhost_dev.acked_features =3D vdev->guest_features; + ret =3D vhost_dev_start(&rpmb->vhost_dev, vdev); + if (ret < 0) { + error_report("Error starting vhost-user-rpmb: %d", -ret); + goto err_guest_notifiers; + } + + /* + * guest_notifier_mask/pending not used yet, so just unmask + * everything here. virtio-pci will do the right thing by + * enabling/disabling irqfd. + */ + for (i =3D 0; i < rpmb->vhost_dev.nvqs; i++) { + vhost_virtqueue_mask(&rpmb->vhost_dev, vdev, i, false); + } + + return; + +err_guest_notifiers: + k->set_guest_notifiers(qbus->parent, rpmb->vhost_dev.nvqs, false); +err_host_notifiers: + vhost_dev_disable_notifiers(&rpmb->vhost_dev, vdev); +} + +static void vurpmb_stop(VirtIODevice *vdev) +{ + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusClass *k =3D VIRTIO_BUS_GET_CLASS(qbus); + int ret; + + if (!k->set_guest_notifiers) { + return; + } + + vhost_dev_stop(&rpmb->vhost_dev, vdev); + + ret =3D k->set_guest_notifiers(qbus->parent, rpmb->vhost_dev.nvqs, fal= se); + if (ret < 0) { + error_report("vhost guest notifier cleanup failed: %d", ret); + return; + } + + vhost_dev_disable_notifiers(&rpmb->vhost_dev, vdev); +} + +static void vurpmb_set_status(VirtIODevice *vdev, uint8_t status) +{ + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + bool should_start =3D status & VIRTIO_CONFIG_S_DRIVER_OK; + + if (!vdev->vm_running) { + should_start =3D false; + } + + if (rpmb->vhost_dev.started =3D=3D should_start) { + return; + } + + if (should_start) { + vurpmb_start(vdev); + } else { + vurpmb_stop(vdev); + } +} + +static uint64_t vurpmb_get_features(VirtIODevice *vdev, + uint64_t requested_features, + Error **errp) +{ + /* No feature bits used yet */ + return requested_features; +} + +static void vurpmb_handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + /* + * Not normally called; it's the daemon that handles the queue; + * however virtio's cleanup path can call this. + */ +} + +static void vurpmb_guest_notifier_mask(VirtIODevice *vdev, int idx, + bool mask) +{ + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + vhost_virtqueue_mask(&rpmb->vhost_dev, vdev, idx, mask); +} + +static bool vurpmb_guest_notifier_pending(VirtIODevice *vdev, int idx) +{ + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + return vhost_virtqueue_pending(&rpmb->vhost_dev, idx); +} + +/* + * Chardev connect/disconnect events + */ + +static int vurpmb_handle_config_change(struct vhost_dev *dev) +{ + int ret; + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(dev->vdev); + + ret =3D vhost_dev_get_config(dev, (uint8_t *)&rpmb->conf.config, + sizeof(struct virtio_rpmb_config)); + if (ret < 0) { + error_report("get config space failed"); + return -1; + } + + return 0; +} + +const VhostDevConfigOps rpmb_ops =3D { + .vhost_dev_config_notifier =3D vurpmb_handle_config_change, +}; + +static int vurpmb_connect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + + if (rpmb->connected) { + return 0; + } + rpmb->connected =3D true; + + /* restore vhost state */ + if (virtio_device_started(vdev, vdev->status)) { + vurpmb_start(vdev); + } + + return 0; +} + +static void vurpmb_disconnect(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + + if (!rpmb->connected) { + return; + } + rpmb->connected =3D false; + + if (rpmb->vhost_dev.started) { + vurpmb_stop(vdev); + } + + vhost_dev_cleanup(&rpmb->vhost_dev); +} + +static void vurpmb_event(void *opaque, QEMUChrEvent event) +{ + DeviceState *dev =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(vdev); + + switch (event) { + case CHR_EVENT_OPENED: + if (vurpmb_connect(dev) < 0) { + qemu_chr_fe_disconnect(&rpmb->conf.chardev); + return; + } + break; + case CHR_EVENT_CLOSED: + vurpmb_disconnect(dev); + break; + case CHR_EVENT_BREAK: + case CHR_EVENT_MUX_IN: + case CHR_EVENT_MUX_OUT: + /* Ignore */ + break; + } +} + +static void do_vhost_user_cleanup(VirtIODevice *vdev, VHostUserRPMB *rpmb) +{ + vhost_user_cleanup(&rpmb->vhost_user); + virtio_delete_queue(rpmb->req_vq); + virtio_cleanup(vdev); + g_free(rpmb->vhost_dev.vqs); + rpmb->vhost_dev.vqs =3D NULL; +} + + +static void vurpmb_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(dev); + int ret; + + if (!rpmb->conf.chardev.chr) { + error_setg(errp, "missing chardev"); + return; + } + + if (!vhost_user_init(&rpmb->vhost_user, &rpmb->conf.chardev, errp)) { + return; + } + + virtio_init(vdev, "vhost-user-rpmb", VIRTIO_ID_RPMB, + sizeof(struct virtio_rpmb_config)); + + /* One request queue, 4 elements in case we don't do indirect */ + rpmb->req_vq =3D virtio_add_queue(vdev, 4, vurpmb_handle_output); + rpmb->vhost_dev.nvqs =3D 1; + rpmb->vhost_dev.vqs =3D g_new0(struct vhost_virtqueue, rpmb->vhost_dev= .nvqs); + ret =3D vhost_dev_init(&rpmb->vhost_dev, &rpmb->vhost_user, + VHOST_BACKEND_TYPE_USER, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "vhost_dev_init failed"); + do_vhost_user_cleanup(vdev, rpmb); + } + + /* + * At this point the next event we will get is a connection from + * the daemon on the control socket. + */ + + qemu_chr_fe_set_handlers(&rpmb->conf.chardev, NULL, NULL, vurpmb_even= t, + NULL, (void *)dev, NULL, true); + + return; +} + +static void vurpmb_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VHostUserRPMB *rpmb =3D VHOST_USER_RPMB(dev); + + /* This will stop vhost backend if appropriate. */ + vurpmb_set_status(vdev, 0); + + do_vhost_user_cleanup(vdev, rpmb); +} + +static const VMStateDescription vurpmb_vmstate =3D { + .name =3D "vhost-user-rpmb", + .unmigratable =3D 1, +}; + +static Property vurpmb_properties[] =3D { + DEFINE_PROP_CHR("chardev", VHostUserRPMB, conf.chardev), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vurpmb_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, vurpmb_properties); + dc->vmsd =3D &vurpmb_vmstate; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + vdc->realize =3D vurpmb_device_realize; + vdc->unrealize =3D vurpmb_device_unrealize; + vdc->get_features =3D vurpmb_get_features; + vdc->get_config =3D vurpmb_get_config; + vdc->set_status =3D vurpmb_set_status; + vdc->guest_notifier_mask =3D vurpmb_guest_notifier_mask; + vdc->guest_notifier_pending =3D vurpmb_guest_notifier_pending; +} + +static const TypeInfo vurpmb_info =3D { + .name =3D TYPE_VHOST_USER_RPMB, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VHostUserRPMB), + .class_init =3D vurpmb_class_init, +}; + +static void vurpmb_register_types(void) +{ + type_register_static(&vurpmb_info); +} + +type_init(vurpmb_register_types) diff --git a/hw/block/Kconfig b/hw/block/Kconfig index 2d17f481adc6..12e21870847a 100644 --- a/hw/block/Kconfig +++ b/hw/block/Kconfig @@ -38,5 +38,10 @@ config VHOST_USER_BLK default y if VIRTIO_PCI depends on VIRTIO && VHOST_USER && LINUX =20 +config VHOST_USER_RPMB + bool + default y + depends on VIRTIO && VHOST_USER + config SWIM bool diff --git a/hw/block/meson.build b/hw/block/meson.build index 78cad8f7cba1..114222f18424 100644 --- a/hw/block/meson.build +++ b/hw/block/meson.build @@ -17,5 +17,6 @@ softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('n= vme.c')) =20 specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-= blk.c')) +specific_ss.add(when: 'CONFIG_VHOST_USER_RPMB', if_true: files('vhost-user= -rpmb.c')) =20 subdir('dataplane') --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038586; cv=none; d=zohomail.com; s=zohoarc; b=FVWBeFcYjo9IKOEyc4lADdY9ymxVZrAkBc2rvUb71uSAR2rFuiurwJoW322ew+7WpbG+dqDDRlGue5HkXpdSlJzUFEZmcZPVlfB3mby4mYiNNipf1RyHbEZtyN3xBfklS8+09/+MN5kTGUeW/VvItHwFHI2H4Z1yvnzukZFjP2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038586; 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=87z//cD5ketSzCXz9JVIdviJkCIdGgLMY4qP1K0Kw40=; b=XNB9TrgTWxVFQws5hGhVM14rHHOglHoVRpsafz6mjwbO4JT3uA/VRPk3s93st1R0G7xFo21+C4M8Jk4wci3//OG+9ZO+u0jlj2JK7KGnh/ORoab7+URhuZ0kY6MbeObm8aLF9qf6oaMQn+lcn2konqL5bwi+IZE9a/aLw1CafMs= 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 1601038586370889.2953257889321; Fri, 25 Sep 2020 05:56:26 -0700 (PDT) Received: from localhost ([::1]:47938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnGz-0004ka-0S for importer@patchew.org; Fri, 25 Sep 2020 08:56:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCj-0007Z1-H0 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:01 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:36272) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCe-0001Nq-IR for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:01 -0400 Received: by mail-wm1-x341.google.com with SMTP id e2so3182990wme.1 for ; Fri, 25 Sep 2020 05:51:56 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h3sm3094150wrq.0.2020.09.25.05.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:51 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 73B101FF8F; Fri, 25 Sep 2020 13:51:48 +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=87z//cD5ketSzCXz9JVIdviJkCIdGgLMY4qP1K0Kw40=; b=Zfnm6T2pDEvo/aiIj0k4PRMgOcmLUaD57bfdPABvJlchpHAWFm8Sxky8kEMM0W354v hjKwaXMxltd3o/PS7J7d79CPlCSTbl/FN+0y5i08Md4ooRI98Le4U5BYg2iCMibq8ko0 fifFGDyfGiLs0ffg6xAjUF2dygYiU9qKK7Xq3Hp/zCNy3VSg9FpT6XGJ2v36T86xs56G rVJ0S3MjCun1FIO9ClkhyZfapnHi3fNqtE0dqLSoX362Bshjs+nodsNjT7tIHehOhNIj vLlkbarQtbtUs+ZiYrg6yXtPJ73FDiqRAtgYtqgZSMs5rGTAR4pdSu9oDcRoXY9/YwDm cCOA== 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=87z//cD5ketSzCXz9JVIdviJkCIdGgLMY4qP1K0Kw40=; b=sFvvr8SaSGqvaYkk9VXiG4w7/jyNIdUX3W49EELRJ0o/8hUHcZ6271m/noiJJAGyxL DtbBsaQRkUtyptoZYYJo9z6qJeZ35xjx+a7Uxz7+ldOYhSm6agryTfJ/0G/Pw7n8NWoa pBG/iFZAqvCFQ5Iiz+T7C48eqezRPwpfbcc18icc8mJOjLGEINNqEOQQcRNtEnYdDkT8 Yy4XDtGGbw34sOdbIN3sBwLjgHIMkwlIpvpcX2KSFeQEV6NpICrIzR07bZgjpnwUlsua G0JtseGskOsBvPm7rwX5sZzzlHMIlj5j3teBOguGGT+IMzbbyNixaG/DTBzfvkVByUUw ZbRQ== X-Gm-Message-State: AOAM531i/do/9tjY7NrrnW5sDYZM5+0/IN3vaEajViO81ckm6W6SFOy6 n0zbGuxof+Y/gqbsRv7dbL/D2A== X-Google-Smtp-Source: ABdhPJwKP0PaoMjwzBkKR4DsYdC/a+SHjJ54z0qEhlhD4wxQ/i2xT2ySLHPvdDCL+xLk2E+vOzWalQ== X-Received: by 2002:a7b:ce86:: with SMTP id q6mr3139106wmj.163.1601038315224; Fri, 25 Sep 2020 05:51:55 -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 03/19] hw/virtio: move virtio-pci.h into shared include space Date: Fri, 25 Sep 2020 13:51:31 +0100 Message-Id: <20200925125147.26943-4-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::341; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x341.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, "Michael S. Tsirkin" , David Hildenbrand , "Dr. David Alan Gilbert" , Raphael Norwitz , takahiro.akashi@linaro.org, Stefan Hajnoczi , Eric Auger , 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) This allows other device classes that will be exposed via PCI to be able to do so in the appropriate hw/ directory. I resisted the temptation to re-order headers to be more aesthetically pleasing. Signed-off-by: Alex Benn=C3=A9e --- {hw =3D> include/hw}/virtio/virtio-pci.h | 0 hw/virtio/vhost-scsi-pci.c | 2 +- hw/virtio/vhost-user-blk-pci.c | 2 +- hw/virtio/vhost-user-fs-pci.c | 2 +- hw/virtio/vhost-user-input-pci.c | 2 +- hw/virtio/vhost-user-scsi-pci.c | 2 +- hw/virtio/vhost-user-vsock-pci.c | 2 +- hw/virtio/vhost-vsock-pci.c | 2 +- hw/virtio/virtio-9p-pci.c | 2 +- hw/virtio/virtio-balloon-pci.c | 2 +- hw/virtio/virtio-blk-pci.c | 2 +- hw/virtio/virtio-input-host-pci.c | 2 +- hw/virtio/virtio-input-pci.c | 2 +- hw/virtio/virtio-iommu-pci.c | 2 +- hw/virtio/virtio-net-pci.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio-rng-pci.c | 2 +- hw/virtio/virtio-scsi-pci.c | 2 +- hw/virtio/virtio-serial-pci.c | 2 +- 19 files changed, 18 insertions(+), 18 deletions(-) rename {hw =3D> include/hw}/virtio/virtio-pci.h (100%) diff --git a/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h similarity index 100% rename from hw/virtio/virtio-pci.h rename to include/hw/virtio/virtio-pci.h diff --git a/hw/virtio/vhost-scsi-pci.c b/hw/virtio/vhost-scsi-pci.c index cb71a294faaf..08980bc23bdb 100644 --- a/hw/virtio/vhost-scsi-pci.c +++ b/hw/virtio/vhost-scsi-pci.c @@ -21,7 +21,7 @@ #include "hw/virtio/vhost-scsi.h" #include "qapi/error.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" =20 typedef struct VHostSCSIPCI VHostSCSIPCI; diff --git a/hw/virtio/vhost-user-blk-pci.c b/hw/virtio/vhost-user-blk-pci.c index 33b404d8a225..eef8641a9891 100644 --- a/hw/virtio/vhost-user-blk-pci.c +++ b/hw/virtio/vhost-user-blk-pci.c @@ -26,7 +26,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" =20 typedef struct VHostUserBlkPCI VHostUserBlkPCI; diff --git a/hw/virtio/vhost-user-fs-pci.c b/hw/virtio/vhost-user-fs-pci.c index 8bb389bd282a..777249e8bc4d 100644 --- a/hw/virtio/vhost-user-fs-pci.c +++ b/hw/virtio/vhost-user-fs-pci.c @@ -14,7 +14,7 @@ #include "qemu/osdep.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-user-fs.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" =20 struct VHostUserFSPCI { diff --git a/hw/virtio/vhost-user-input-pci.c b/hw/virtio/vhost-user-input-= pci.c index c9d3e9113a5e..b858898a3630 100644 --- a/hw/virtio/vhost-user-input-pci.c +++ b/hw/virtio/vhost-user-input-pci.c @@ -9,7 +9,7 @@ #include "hw/virtio/virtio-input.h" #include "qapi/error.h" #include "qemu/error-report.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" =20 typedef struct VHostUserInputPCI VHostUserInputPCI; diff --git a/hw/virtio/vhost-user-scsi-pci.c b/hw/virtio/vhost-user-scsi-pc= i.c index d5343412a11c..75882e3cf943 100644 --- a/hw/virtio/vhost-user-scsi-pci.c +++ b/hw/virtio/vhost-user-scsi-pci.c @@ -30,7 +30,7 @@ #include "hw/pci/msix.h" #include "hw/loader.h" #include "sysemu/kvm.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" =20 typedef struct VHostUserSCSIPCI VHostUserSCSIPCI; diff --git a/hw/virtio/vhost-user-vsock-pci.c b/hw/virtio/vhost-user-vsock-= pci.c index 763f89984e91..a50845ea87a3 100644 --- a/hw/virtio/vhost-user-vsock-pci.c +++ b/hw/virtio/vhost-user-vsock-pci.c @@ -10,7 +10,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-user-vsock.h" #include "qom/object.h" diff --git a/hw/virtio/vhost-vsock-pci.c b/hw/virtio/vhost-vsock-pci.c index e56067b42781..35773fbcb3b0 100644 --- a/hw/virtio/vhost-vsock-pci.c +++ b/hw/virtio/vhost-vsock-pci.c @@ -13,7 +13,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/vhost-vsock.h" #include "qemu/module.h" diff --git a/hw/virtio/virtio-9p-pci.c b/hw/virtio/virtio-9p-pci.c index e07adcd9ea78..94c14f0b98c9 100644 --- a/hw/virtio/virtio-9p-pci.c +++ b/hw/virtio/virtio-9p-pci.c @@ -15,7 +15,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/9pfs/virtio-9p.h" #include "hw/qdev-properties.h" #include "qemu/module.h" diff --git a/hw/virtio/virtio-balloon-pci.c b/hw/virtio/virtio-balloon-pci.c index a2c5cc7207a9..8d5a212b94cd 100644 --- a/hw/virtio/virtio-balloon-pci.c +++ b/hw/virtio/virtio-balloon-pci.c @@ -14,7 +14,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-balloon.h" #include "qapi/error.h" diff --git a/hw/virtio/virtio-blk-pci.c b/hw/virtio/virtio-blk-pci.c index 9d5795810c36..9743bee965af 100644 --- a/hw/virtio/virtio-blk-pci.c +++ b/hw/virtio/virtio-blk-pci.c @@ -19,7 +19,7 @@ =20 #include "hw/qdev-properties.h" #include "hw/virtio/virtio-blk.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qapi/error.h" #include "qemu/module.h" #include "qom/object.h" diff --git a/hw/virtio/virtio-input-host-pci.c b/hw/virtio/virtio-input-hos= t-pci.c index 0ac360de4f34..cf8a9cf9e8db 100644 --- a/hw/virtio/virtio-input-host-pci.c +++ b/hw/virtio/virtio-input-host-pci.c @@ -8,7 +8,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-input.h" #include "qemu/module.h" #include "qom/object.h" diff --git a/hw/virtio/virtio-input-pci.c b/hw/virtio/virtio-input-pci.c index 85acd3d2ebb4..d208df68af5f 100644 --- a/hw/virtio/virtio-input-pci.c +++ b/hw/virtio/virtio-input-pci.c @@ -8,7 +8,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-input.h" #include "qemu/module.h" diff --git a/hw/virtio/virtio-iommu-pci.c b/hw/virtio/virtio-iommu-pci.c index 76540e57b104..022447b5a469 100644 --- a/hw/virtio/virtio-iommu-pci.c +++ b/hw/virtio/virtio-iommu-pci.c @@ -11,7 +11,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-iommu.h" #include "hw/qdev-properties.h" #include "qapi/error.h" diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c index 292d13d27815..954b6fbf2d58 100644 --- a/hw/virtio/virtio-net-pci.c +++ b/hw/virtio/virtio-net-pci.c @@ -19,7 +19,7 @@ =20 #include "hw/qdev-properties.h" #include "hw/virtio/virtio-net.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qapi/error.h" #include "qemu/module.h" #include "qom/object.h" diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 5bc769f685ce..507cb57c410f 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -32,7 +32,7 @@ #include "hw/pci/msix.h" #include "hw/loader.h" #include "sysemu/kvm.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qemu/range.h" #include "hw/virtio/virtio-bus.h" #include "qapi/visitor.h" diff --git a/hw/virtio/virtio-rng-pci.c b/hw/virtio/virtio-rng-pci.c index c1f916268be7..151ece6f946a 100644 --- a/hw/virtio/virtio-rng-pci.c +++ b/hw/virtio/virtio-rng-pci.c @@ -11,7 +11,7 @@ =20 #include "qemu/osdep.h" =20 -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "hw/virtio/virtio-rng.h" #include "qapi/error.h" #include "qemu/module.h" diff --git a/hw/virtio/virtio-scsi-pci.c b/hw/virtio/virtio-scsi-pci.c index 97fab742368a..e8e3442f3828 100644 --- a/hw/virtio/virtio-scsi-pci.c +++ b/hw/virtio/virtio-scsi-pci.c @@ -18,7 +18,7 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-scsi.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" =20 typedef struct VirtIOSCSIPCI VirtIOSCSIPCI; diff --git a/hw/virtio/virtio-serial-pci.c b/hw/virtio/virtio-serial-pci.c index 35bcd961c988..cea31adcc4c6 100644 --- a/hw/virtio/virtio-serial-pci.c +++ b/hw/virtio/virtio-serial-pci.c @@ -20,7 +20,7 @@ #include "hw/qdev-properties.h" #include "hw/virtio/virtio-serial.h" #include "qemu/module.h" -#include "virtio-pci.h" +#include "hw/virtio/virtio-pci.h" #include "qom/object.h" =20 typedef struct VirtIOSerialPCI VirtIOSerialPCI; --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038562; cv=none; d=zohomail.com; s=zohoarc; b=KyJ3Yl1EworpSXcsh0hIDAX1FmjxBLWKeaT3eAtCjXwLO34muFpKJ2zaZtYcMmcmjDaDCICTMxdZ/ss9waZ42OLEV7Nt7FMSZvGszhB75eqtR9j4y99m0TpxS4nHwgo1yeaJh4JhNiweRa5Yn/964D9NbKqavX2qCS4kEfiiXKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038562; 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=qmK72LzpAk+sHPJlMHFLJRJNfxPeFEWb03L+Le08bE4=; b=lCFbpcz9Wd2jDY4HUeU0u5bZZ45Z9V9mcalkkkUQx9hHLLt2XHG+YMvVBb23S6NZk4PPYxhI9YZYMfuYLg7F0li/kwQGH5TzmJc5xA9SvG2qLp87SJCikxfMWHt+u97sa1SQ9QXNr9VygVmCRLac+/3fPzxx98jgDpUAl1wMXaI= 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 1601038562836342.8779322175735; Fri, 25 Sep 2020 05:56:02 -0700 (PDT) Received: from localhost ([::1]:46182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnGb-0003z1-AG for importer@patchew.org; Fri, 25 Sep 2020 08:56:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCi-0007Vm-CK for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:00 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCf-0001O1-WA for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:51:59 -0400 Received: by mail-wr1-x443.google.com with SMTP id z1so3501974wrt.3 for ; Fri, 25 Sep 2020 05:51:57 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id i6sm3021447wra.1.2020.09.25.05.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:51 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8D3271FF90; Fri, 25 Sep 2020 13:51:48 +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=qmK72LzpAk+sHPJlMHFLJRJNfxPeFEWb03L+Le08bE4=; b=SgRYZHcF/mHGDtqMaPrLM0TYZ4xvkmAnBYe9mEz2RmcztJXqrPMmpSYzj7wQ+6EM+k jay8naQYyZIakKg8pCmwg7IMR7/REwAiaWv+57mAuwViVCmZI7kZX2LABNuRTGsKhUJb 0uHj4sFTab/oGjXCbWlOVulMvO0vGOI1c1KkwHwYVGGs1CpzTQp4yy43A1ydFGsfIIHQ J2/SvtegF2jptFk1nfXaABVWoGFr9UoITuVTGBU9wTpoMkbwpiCPL12YRKlOsSwVOjR9 P1RmA1HPPWwWmf3+WknjmWex3xsp33lqRXlt2IjxCUCSl67xAANBNCdr5cXh01k5471Q epdA== 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=qmK72LzpAk+sHPJlMHFLJRJNfxPeFEWb03L+Le08bE4=; b=XU2F4S0A9H2ClKE+NBhdje7RqrMm3yk28y5/TKV06WOmHwlhWQ+LoxA0LfhSjeiI9u /bkE7utJv5HgomDzn+awlfw1T8xQNtgSlkUknnI22p7CGaRcqWKrjjqEcOuLcRUNhs1b T1B/rO08SUzs448PvJ1/WXvNDRCty02r5jJxTuPKbqyeS/jmmBtYLxlPyaTU6OnTPh48 F9ZIxSZ5PkbbiKLAkM+7uqSVUHByuvG5rzXqoQkHIxiAk5O6sK1i7S2RJxtuSz2VHfcx 6106cxSJtafZFHQfWv+kAyTa+MG5QvMjVl+GL15VRLVsexTeJz6HRe5LYYAXvSBF1MH5 smpQ== X-Gm-Message-State: AOAM531hZqlCE5LBBa0+cN3boQGykSBpYoKTEL7xWit62BAdHWywkYbJ sPphNTuCK6lydcNsj6g2w9NVyA== X-Google-Smtp-Source: ABdhPJyVMN0X63SItNReY5JJEsFfyQ3owfll7yNWGpQiY0FQLy7Jdcq4fU/KL11JP3iunvtBLpKjzA== X-Received: by 2002:adf:e6c2:: with SMTP id y2mr4591930wrm.117.1601038316477; Fri, 25 Sep 2020 05:51:56 -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 04/19] hw/block: add vhost-user-rpmb-pci boilerplate Date: Fri, 25 Sep 2020 13:51:32 +0100 Message-Id: <20200925125147.26943-5-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::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x443.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: Kevin Wolf , jean-philippe@linaro.org, "open list:Block layer core" , "Michael S. Tsirkin" , Max Reitz , 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) This allows is to instantiate a vhost-user-rpmb device as part of a PCI bus. It is mostly boilerplate which looks pretty similar to the vhost-user-fs-pci device if you squint. Signed-off-by: Alex Benn=C3=A9e --- - enable use IOEVENTFD flag - swap obj set bool args --- hw/block/vhost-user-rpmb-pci.c | 82 ++++++++++++++++++++++++++++++++++ hw/block/meson.build | 2 + 2 files changed, 84 insertions(+) create mode 100644 hw/block/vhost-user-rpmb-pci.c diff --git a/hw/block/vhost-user-rpmb-pci.c b/hw/block/vhost-user-rpmb-pci.c new file mode 100644 index 000000000000..f0518305a1d9 --- /dev/null +++ b/hw/block/vhost-user-rpmb-pci.c @@ -0,0 +1,82 @@ +/* + * Vhost-user RPMB virtio device PCI glue + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-rpmb.h" +#include "hw/virtio/virtio-pci.h" + +struct VHostUserRPMBPCI { + VirtIOPCIProxy parent_obj; + VHostUserRPMB vdev; +}; + +typedef struct VHostUserRPMBPCI VHostUserRPMBPCI; + +#define TYPE_VHOST_USER_RPMB_PCI "vhost-user-rpmb-pci-base" + +#define VHOST_USER_RPMB_PCI(obj) \ + OBJECT_CHECK(VHostUserRPMBPCI, (obj), TYPE_VHOST_USER_RPMB_PCI) + +static Property vurpmb_pci_properties[] =3D { + DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, + DEV_NVECTORS_UNSPECIFIED), + DEFINE_PROP_END_OF_LIST(), +}; + +static void vurpmb_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VHostUserRPMBPCI *dev =3D VHOST_USER_RPMB_PCI(vpci_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + if (vpci_dev->nvectors =3D=3D DEV_NVECTORS_UNSPECIFIED) { + vpci_dev->nvectors =3D 1; + } + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), "realized", true, errp); +} + +static void vurpmb_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioPCIClass *k =3D VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k =3D PCI_DEVICE_CLASS(klass); + k->realize =3D vurpmb_pci_realize; + set_bit(DEVICE_CATEGORY_STORAGE, dc->categories); + device_class_set_props(dc, vurpmb_pci_properties); + pcidev_k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id =3D 0; /* Set by virtio-pci based on virtio id */ + pcidev_k->revision =3D 0x00; + pcidev_k->class_id =3D PCI_CLASS_STORAGE_OTHER; +} + +static void vurpmb_pci_instance_init(Object *obj) +{ + VHostUserRPMBPCI *dev =3D VHOST_USER_RPMB_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VHOST_USER_RPMB); +} + +static const VirtioPCIDeviceTypeInfo vurpmb_pci_info =3D { + .base_name =3D TYPE_VHOST_USER_RPMB_PCI, + .non_transitional_name =3D "vhost-user-rpmb-pci", + .instance_size =3D sizeof(VHostUserRPMBPCI), + .instance_init =3D vurpmb_pci_instance_init, + .class_init =3D vurpmb_pci_class_init, +}; + +static void vurpmb_pci_register(void) +{ + virtio_pci_types_register(&vurpmb_pci_info); +} + +type_init(vurpmb_pci_register); diff --git a/hw/block/meson.build b/hw/block/meson.build index 114222f18424..0b2d10201e28 100644 --- a/hw/block/meson.build +++ b/hw/block/meson.build @@ -18,5 +18,7 @@ softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('n= vme.c')) specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-= blk.c')) specific_ss.add(when: 'CONFIG_VHOST_USER_RPMB', if_true: files('vhost-user= -rpmb.c')) +specific_ss.add(when: ['CONFIG_VHOST_USER_RPMB', 'CONFIG_VIRTIO_PCI' ], + if_true: files('vhost-user-rpmb-pci.c')) =20 subdir('dataplane') --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038549; cv=none; d=zohomail.com; s=zohoarc; b=KDeMK6QvuKtm/qXH4pWQCJYUGr1fpBm85Onmvk4j9DzOR1QFy5mxklZcag+AYlccUFVVFt7oVxI9mXLFUoQcuuJRfwJy+jPokTthHFc3fSNIiXKLG0QOtjYgOfWOK2LAcqwNwYlfSErleI8t6DCE05/zb4jsNtrVXSMOrMj6im4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038549; 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=XCceP6Edp7P+SbIMUL/HUpL1UYE1lgoGhcHsF49MNZU=; b=CzoFW1z7TjHqT/gYWCt8k3KOHKrImYJaCbFgHE3GgGNDPZWT11acrQVYB4MNDUGAKJNdKzR0n8ZHjYeTCdunpj1xNJjT1nTm4bNf9tLrgRhfm8yUJ01nkO2QDYAd8hx+3/RNCB25ROf+cL9/L1WQw/+22suh6+5T3aPqb2dJj6Y= 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 1601038549140962.3169522082871; Fri, 25 Sep 2020 05:55:49 -0700 (PDT) Received: from localhost ([::1]:45280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnGN-0003Zh-Ni for importer@patchew.org; Fri, 25 Sep 2020 08:55:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCk-0007b9-G4 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:02 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:53689) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCi-0001OV-CN for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:02 -0400 Received: by mail-wm1-x342.google.com with SMTP id x23so2927024wmi.3 for ; Fri, 25 Sep 2020 05:51:59 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l17sm2756361wme.11.2020.09.25.05.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:53 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A74381FF91; Fri, 25 Sep 2020 13:51:48 +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=XCceP6Edp7P+SbIMUL/HUpL1UYE1lgoGhcHsF49MNZU=; b=xkrWq1Cgr+Bj+7+g3Nsr1J0dGpvBwK6/soDxBuin8vmQu03hos6U4PAOcTMjmMKRL7 053HDpQ9gKsC4gqYY+hhtpxiQgwtpPVev+YAkW9hgL6wkv9kWCiGCvJi8zl30d0e+KN6 RS79a41HZOeJk5EJB/LJFupJXSDYjkWE5/BHvYqdnpz5FFFXI9c4VXoh0AzDfu1bROCy DrU82EgjSbMCg5u/pXqXgBA5BFgug2JbKSIkxQNuWFzUZNsEqPaDmHBbwtW9VVjt6cHu OZhTEVNxe8LVkTWgxAbD1ep09yeMIbCDKH+dOq7JOm9Rk8Y/y9Vl87jYYCaRIXmzaAQt nxGw== 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=XCceP6Edp7P+SbIMUL/HUpL1UYE1lgoGhcHsF49MNZU=; b=JPpJ88tNRrV4YgRvbDd10oQZqaueYKmwS/mExqTI6XFq8vPKx/tZ8AusY2PAIa9rk/ aZEGA7nQZwZy/NaAFUvJEBzZEHFcpzhf48Y0GuOaO5ycpECXjhqHd5fN83eCIOmN/l/5 y6gLPffo7qOJZx4MoyKa1vdH3/29BzLBkvGJL2EHK7QPpD/XtEwOJXHgIN0rdl3KpLaC ycQjrZJNQAga0oICm1Ov3LuHavLiK9WTVLH40J839O3dqBuHsTA8owWRNo5GpDACuD+O ZjY6lrhf8GejB4v7mlUibqBpUSKD8BtuZgCHomWYnBKp5Fh2w4LTWj7Q4hft7CZAZz9e JgVQ== X-Gm-Message-State: AOAM531iL0ju1nDOqAMVSPu8yKMvmIPhxRNOXBwtgxxP0V1SJNtfX50v 6yg9GOS0wy+cEojQnmOo0TmE+Q== X-Google-Smtp-Source: ABdhPJxbsS2HesAWoB4xN00MHkBIOSc+8lw3iA/LUtk3G3s0NUGb1qyDjlBEXfv2nmJedBiuG7Rhjw== X-Received: by 2002:a1c:dd87:: with SMTP id u129mr2979946wmg.172.1601038318896; Fri, 25 Sep 2020 05:51:58 -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 05/19] virtio-pci: add notification trace points Date: Fri, 25 Sep 2020 13:51:33 +0100 Message-Id: <20200925125147.26943-6-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::342; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x342.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, "Michael S. Tsirkin" , 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) Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/virtio/virtio-pci.c | 3 +++ hw/virtio/trace-events | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 507cb57c410f..33a40e31d955 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -36,6 +36,7 @@ #include "qemu/range.h" #include "hw/virtio/virtio-bus.h" #include "qapi/visitor.h" +#include "trace.h" =20 #define VIRTIO_PCI_REGION_SIZE(dev) VIRTIO_PCI_CONFIG_OFF(msix_present= (dev)) =20 @@ -1340,6 +1341,7 @@ static void virtio_pci_notify_write(void *opaque, hwa= ddr addr, unsigned queue =3D addr / virtio_pci_queue_mem_mult(proxy); =20 if (vdev !=3D NULL && queue < VIRTIO_QUEUE_MAX) { + trace_virtio_pci_notify_write(addr, val, size); virtio_queue_notify(vdev, queue); } } @@ -1353,6 +1355,7 @@ static void virtio_pci_notify_write_pio(void *opaque,= hwaddr addr, unsigned queue =3D val; =20 if (vdev !=3D NULL && queue < VIRTIO_QUEUE_MAX) { + trace_virtio_pci_notify_write_pio(addr, val, size); virtio_queue_notify(vdev, queue); } } diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 845200bf109d..189972b9213a 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -55,7 +55,12 @@ virtio_mmio_guest_page(uint64_t size, int shift) "guest = page size 0x%" PRIx64 " virtio_mmio_queue_write(uint64_t value, int max_size) "mmio_queue write 0x= %" PRIx64 " max %d" virtio_mmio_setting_irq(int level) "virtio_mmio setting IRQ %d" =20 -# virtio-iommu.c +# virtio-pci.c +virtio_pci_notify(uint16_t vector) "virtio_pci_notify vec 0x%x" +virtio_pci_notify_write(uint64_t addr, uint64_t val, unsigned int size) "0= x%" PRIx64" =3D 0x%" PRIx64 " (%d)" +virtio_pci_notify_write_pio(uint64_t addr, uint64_t val, unsigned int size= ) "0x%" PRIx64" =3D 0x%" PRIx64 " (%d)" + +# hw/virtio/virtio-iommu.c virtio_iommu_device_reset(void) "reset!" virtio_iommu_get_features(uint64_t features) "device supports features=3D0= x%"PRIx64 virtio_iommu_device_status(uint8_t status) "driver status =3D %d" --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038678; cv=none; d=zohomail.com; s=zohoarc; b=TaOwM4fkVX3uUec9oEF3r8EwsykOj9zwsVa9CzPpncTHI0GE16akFPYmSc4xcaDsYV4+zpx9eK7M6j/O1qolzmWBQhg54g+Ij2toMwT+HwrG9Ud63BykmxCUYjRpkX+0TEdqZmA/jVFzKoKiBWZ7RQFuHjrrB25GNPsccU93bHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038678; 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=qsQZO642QNM9thsI3rY2HZwoa6pjzpWob+CVTQWTY9k=; b=UwLZoDZgUvh4lNeeWcd6SCBUxdEXfKDzmE9hhLXIXQoDfu9ciGkdVWMvitILg4B5/8+WYeKptccdDwZQxqFVu/QG6e4zGN1OZ7IYiwpshXTCmh3kpdln1KldYhQZ1CFpAat/NMbsudbjPROiXRDyxEC2pG37jDvn3xv4FUfoyC0= 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 1601038678348348.2556252957463; Fri, 25 Sep 2020 05:57:58 -0700 (PDT) Received: from localhost ([::1]:55586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnIT-0007rm-1Y for importer@patchew.org; Fri, 25 Sep 2020 08:57:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCl-0007dK-Ce for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:03 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34380) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCj-0001Oo-DX for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:03 -0400 Received: by mail-wr1-x443.google.com with SMTP id t10so3526679wrv.1 for ; Fri, 25 Sep 2020 05:52:00 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l18sm2730665wrp.84.2020.09.25.05.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:53 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C544D1FF92; Fri, 25 Sep 2020 13:51:48 +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=qsQZO642QNM9thsI3rY2HZwoa6pjzpWob+CVTQWTY9k=; b=UHH9XotPcaYd69YG2moOspEe8L59ggJkDB9j8hC7qbik1KRbkYDtM6C4EsDe/h0MLq Sq4RMjWheINojM95Qcm/GW4lfrhRJINf4TnM+1AinLXgny7ZLW/WYYXl3aEF6GMGS4vE B7UzanlSuTJ+faT1+h1dZiNiabnem737nOmJCmBVT/RvgddxGluHp0DHoyiafjPy78cH kgnXQ61iULB1D2ILTuiZcmEJAvAUx2SOPQjH9uaSeHrUnvhpnV9LVEWBujE/yi1F76mn VZ0+GzOrusr4XWoGZUpP/HvVuqXDStYmZKgkm9FP0Ljkcs7pxxxtNCk7OlbDgnsPjwsO pTVA== 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=qsQZO642QNM9thsI3rY2HZwoa6pjzpWob+CVTQWTY9k=; b=TyU6ozxXGMTwTxNx0TiKZknsw803N46xiuqfpeUf5o9ZA2pbJ4YhVnNnpBOJr+5jd2 6KdoVXMdBoE1BGuH7jlPEWmtEfn4EYYWytOKQ4C4/ZhWXjhlS2m/sEfiyOFCafTwG1hW 3eUcfsAhuo2AddoCqzssuNY9ya8TnAmkCSuxEkzr6+FbBwcO5t/OydatjPbtYdkXh7PO go4nhxxWJmF8b0xv6EPxHxZw5bDazH5viXuYpQWUvHWut1d5q4ir5BQC1eIf7TD7R/Cg 2ZmAl435t6vRIE6W3w/E/sASae/KQip/vFjbFXUa+YXSz6riJouYekZnoxEYTlDIZY1p vbvA== X-Gm-Message-State: AOAM533ew5Sye41WGa37xzPxi81U0oRm7flhs5wRGgmbqa57Lko/hBqy UyYNmydIBOv7R/jd3/lFYjY/0Q== X-Google-Smtp-Source: ABdhPJzxGOLpvB7rUaudCgm/+nAA6NXLFNZlEuBZJJxkQw7M1L981nLdC9hOSy871SGN+c1FCuXWFA== X-Received: by 2002:a5d:5261:: with SMTP id l1mr4316749wrc.193.1601038320023; Fri, 25 Sep 2020 05:52:00 -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 06/19] tools/vhost-user-rpmb: add boilerplate and initial main Date: Fri, 25 Sep 2020 13:51:34 +0100 Message-Id: <20200925125147.26943-7-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::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x443.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) This adds the boilerplate files for a new vhost-user helper called vhost-user-rpmb which will support virtio based RPMB (Replay Protected Memory Block) devices. This commit just adds the initial boilerplate for building the binary with the common vhost-user options. As of this commit the only useful output you get is when running: vhost-user-rpmb --help Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 37 ++++++++++++++++++++++ MAINTAINERS | 5 +++ tools/meson.build | 8 +++++ tools/vhost-user-rpmb/50-qemu-rpmb.json.in | 5 +++ tools/vhost-user-rpmb/meson.build | 11 +++++++ 5 files changed, 66 insertions(+) create mode 100644 tools/vhost-user-rpmb/main.c create mode 100644 tools/vhost-user-rpmb/50-qemu-rpmb.json.in create mode 100644 tools/vhost-user-rpmb/meson.build diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c new file mode 100644 index 000000000000..a40a680a74ca --- /dev/null +++ b/tools/vhost-user-rpmb/main.c @@ -0,0 +1,37 @@ +/* + * VIRTIO RPMB Emulation via vhost-user + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include + +static gchar *socket_path; +static gint socket_fd; +static gboolean print_cap; + +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" }, + { "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}, + { NULL } +}; + +int main (int argc, char *argv[]) +{ + GError *error =3D NULL; + GOptionContext *context; + + context =3D g_option_context_new ("vhost-user-rpmb - vhost-user emulat= ion of RPBM device"); + g_option_context_add_main_entries (context, options, "vhost-user-rpmb"= ); + if (!g_option_context_parse (context, &argc, &argv, &error)) + { + g_print ("option parsing failed: %s\n", error->message); + exit (1); + } + + +} diff --git a/MAINTAINERS b/MAINTAINERS index 3d17cad19aa0..e325c1024a33 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1873,6 +1873,11 @@ F: hw/virtio/virtio-mem-pci.h F: hw/virtio/virtio-mem-pci.c F: include/hw/virtio/virtio-mem.h =20 +virtio-rpmb +M: Alex Benn=C3=A9e +S: Supported +F: tools/vhost-user-rpmb/* + nvme M: Keith Busch M: Klaus Jensen diff --git a/tools/meson.build b/tools/meson.build index 513bd2ff4fd2..408048c6357c 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -8,3 +8,11 @@ have_virtiofsd =3D (have_system and if have_virtiofsd subdir('virtiofsd') endif + +have_virtiorpmb =3D (have_system and + have_tools and + 'CONFIG_LINUX' in config_host) + +if have_virtiorpmb + subdir('vhost-user-rpmb') +endif diff --git a/tools/vhost-user-rpmb/50-qemu-rpmb.json.in b/tools/vhost-user-= rpmb/50-qemu-rpmb.json.in new file mode 100644 index 000000000000..2b033cda567c --- /dev/null +++ b/tools/vhost-user-rpmb/50-qemu-rpmb.json.in @@ -0,0 +1,5 @@ +{ + "description": "QEMU vhost-user-rpmb", + "type": "block", + "binary": "@libexecdir@/vhost-user-rpmb" +} diff --git a/tools/vhost-user-rpmb/meson.build b/tools/vhost-user-rpmb/meso= n.build new file mode 100644 index 000000000000..e0df1b69a3fb --- /dev/null +++ b/tools/vhost-user-rpmb/meson.build @@ -0,0 +1,11 @@ +executable('vhost-user-rpmb', files( + 'main.c'), + dependencies: [glib], + link_with: [libvhost_user], + install: true, + install_dir: get_option('libexecdir')) + +configure_file(input: '50-qemu-rpmb.json.in', + output: '50-qemu-rpmb.json', + configuration: config_host, + install_dir: qemu_datadir / 'vhost-user') --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038576; cv=none; d=zohomail.com; s=zohoarc; b=eAiW+WJQYtAhLRCdvKNgGNHcEqjtpcEHZw0P9O5YYdEScJOOMA+YbdcGc98VpxEI1sGj4L+Vjqo3O/PNtx+iwtDPeE869xQLqb4Q4DWRpGElZOQ3xzrbU0MtUPOfNx86y3cFaOAbaA/gXjtF/IjtW6IocX2xHUrhr3wOCQwSjSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038576; 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=BtOwqygZxNZk6oWCI22F6lqMw1LRPXvFIADZTQl+rOY=; b=jiQLjbW19l+VR2kTEbjVE9uV1gttX61seuIDh9p3l/sM3KxuxHXAGOh1slkM6Ja8osIedsscyUgG8ehS528G4dQfyJ5PfjF7qY20IU9hwrjYfclM90TYKds5WO8YLiftFaWSyGkEs/1kzepb9QsQ15KocwI8KkJArglVX03MQ/g= 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 1601038576263410.7860320651274; Fri, 25 Sep 2020 05:56:16 -0700 (PDT) Received: from localhost ([::1]:46926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnGp-0004Ka-09 for importer@patchew.org; Fri, 25 Sep 2020 08:56:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCn-0007jz-H1 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:05 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:39297) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCl-0001PC-Om for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:05 -0400 Received: by mail-wm1-x32a.google.com with SMTP id b79so3165493wmb.4 for ; Fri, 25 Sep 2020 05:52:03 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h17sm3046659wro.27.2020.09.25.05.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:56 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id DB33B1FF93; Fri, 25 Sep 2020 13:51:48 +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=BtOwqygZxNZk6oWCI22F6lqMw1LRPXvFIADZTQl+rOY=; b=fOjWrSyCvJQYpMmASANN0N5QLGO7rBHdRnm4ZVIiBVZlboHIMioFdOTj8nD0PTwhEv k/IGXoGYu3E5ubzC3bbcoLsONq5pPZuY1RfllMwg2CURFDzpYPe5K0cafBWCDhEU7dhp qp2WvHMxU24jfTi3SacCtzZjqZFRLXpuIkjsf3PZMjqGOEYktpXJZ//HQERRHsxDVfNG F7aQsxtpv9FimpmVRLFaU3JP/oMwKAcJ854HlbhxoZEvitK741+tB/KwWEP9DXYBl+Fy yRcExZhp/9sThFMQ+pFYyy8KLFlqKVS/a4D60ETPCuECkpiOfg6MMpPbJob43Qkdsz+8 FiGg== 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=BtOwqygZxNZk6oWCI22F6lqMw1LRPXvFIADZTQl+rOY=; b=W1AzrZQkuoTR1UxT+Al8bmOX2NH2vHNnzMvl/RjhnQ7JjlIx3Ad1zzFL4yBOTtFeP/ 3PV0XaGC8sIS3agz+JxuTK4dj4uQZzXRFNSv3PZxiEKywLvBISQ4ImpgdgS/AT0vXPkX KOHw6oPUckEXx8/dxXS3jzPicQOkXNdJIu3NpcD0Fhr5SH+i6aFgzpaWFM1G2GcJ5PUu umclrrg6ApNJBlucp7AhY0N2nzhTFS3uaUJJqEziAKDgAV3GdJpHjozhF9qU0U8lcvKF oPe/P8ShLOGff+caMMwONAdwM1uvBNTa6BQ7n0gRTe4/D6Ju6udfBYUP8NHqKEiB0VEG ZB0A== X-Gm-Message-State: AOAM532eT1dsI4YbIyi2SJsa1oFamaXnMyyLhG4xhmr75GOuPzdaZcyH Q0Yo7UNaejpeBGA4t1wB34bcoA== X-Google-Smtp-Source: ABdhPJykzsVoFuABJlyF48BUdTgFdDhu4D6Z6tqvRMH73d8CJkJCXeBVJNsmCMLI+v2nkSCEGVIPrw== X-Received: by 2002:a05:600c:252:: with SMTP id 18mr2846464wmj.63.1601038322276; Fri, 25 Sep 2020 05:52:02 -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 07/19] tools/vhost-user-rpmb: implement --print-capabilities Date: Fri, 25 Sep 2020 13:51:35 +0100 Message-Id: <20200925125147.26943-8-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::32a; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32a.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) A very simple capabilities dump. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index a40a680a74ca..6b1989125bd6 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -7,6 +7,7 @@ */ =20 #include +#include =20 static gchar *socket_path; static gint socket_fd; @@ -20,6 +21,14 @@ static GOptionEntry options[] =3D { NULL } }; =20 +/* Print vhost-user.json backend program capabilities */ +static void print_capabilities(void) +{ + printf("{\n"); + printf(" \"type\": \"block\"\n"); + printf("}\n"); +} + int main (int argc, char *argv[]) { GError *error =3D NULL; @@ -33,5 +42,9 @@ int main (int argc, char *argv[]) exit (1); } =20 + if (print_cap) { + print_capabilities(); + exit(0); + } =20 } --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038760; cv=none; d=zohomail.com; s=zohoarc; b=T24aO7GWSsS9TctRPy8SJlGCYVGfVb7hVQzo7gdk7uEVolawFJeusz6znShq9HwpYtGB3+HiiDicHvoByq9L1p8wJBIlv3j+3UStE6yyKa9R508bHoHqYDgSxj7NFBfpjmYXeydRcqMov3DjH8hn+qkOy5JFDIuUGA4r437zaXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038760; 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=LyX39wHBNrDOQa2NkxK5rhi5dv936oaE8zOOQGpdbek=; b=RWf64XsmO7rY5IF3XQEj0+pLGHNZJ6ikNp7ob3HgBrYa8kzE6eqmjTxohJ9wiPrRe7ZCR2ubhKCd6syodq66poJtAg87J+bccyuFfMvpj8KNWhynTT0dfN4vVss5Pd5Flt7qcJ+/6bD/VhVlFdZzWJJeqcNpId4m2b7LKQ1MjvM= 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 1601038760703190.1154465490838; Fri, 25 Sep 2020 05:59:20 -0700 (PDT) Received: from localhost ([::1]:33836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnJn-000234-6z for importer@patchew.org; Fri, 25 Sep 2020 08:59:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCp-0007n1-Dm for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:08 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:34559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCn-0001QP-5R for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:07 -0400 Received: by mail-wm1-x344.google.com with SMTP id l15so1824725wmh.1 for ; Fri, 25 Sep 2020 05:52:04 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id p3sm2631021wmm.40.2020.09.25.05.51.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:51:56 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 012C21FF96; 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=LyX39wHBNrDOQa2NkxK5rhi5dv936oaE8zOOQGpdbek=; b=EgxvFKsFa+w2EoU101dM4fi2UQcaWDko5usfIsYh+Gc83uVqHoFtK69ClctkN3gJDl rnVMeIXp8+xCE9RCo5iMzUsThofAlgs6Rm9Q4ByzenZSAwdnf0iiBfR90jfEFPUKGz1A zy7cRrTszJzI7fubdVrfIDJmUhrazn4o5HtSnXZ5WKt9ufBN2qmVqJyyG9pViB0mvjrY BV+Z1lYEv3LPAUQETl1XoUldUkzn4GJg+e/c7xB6aiAxUG82aFz1br4s78c7DkP58F7z S2yNPcz7PRWckp92SDxumaDnOH2qcn8hZ/VTpSXRHcYOHd5x3wtv4PB0+Dman0MfvH4L 9jag== 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=LyX39wHBNrDOQa2NkxK5rhi5dv936oaE8zOOQGpdbek=; b=btx8e5M+VLJMm9aKqTV2YFSiFSCt645qFT8qF3G/xTR/vS79eCGpw+OAvh834uJ4yt f98aNZej8L6bmA6oXslvBg34BORVV0Xsntyv9n8UPh409ZlD4N4ndNXw9EL6RSYi2/6i h/kvgqgkRogvwpFZqeZfHBJ4HsNd4ri6/rvrkWUfYMSm9X4NQ/eyEcEODEHptXgTd73o BAQ6hejeMrSqj8K3XbtCrbxDT9tJhHZDu6qZKgR2T0eRfnnMyy8i0GX8rd6kAJtK/iQW sLVkn9XoNRW0CGqsrRCoXKHnGlxltZkfQrHEVqaiRCWf9/ptiHR21nYs23UV61nIZsnE GUxg== X-Gm-Message-State: AOAM531FN7Ww2B0KeGZ9wv0OZkfKV6O45akNUlLUbd093pSJIQuUWhBr wU+6yKXaGRtXqZfbuLp45A61fQ== X-Google-Smtp-Source: ABdhPJxi/v3h2iuMHrsZ3StbC1XR0MKxMeNhamxbZ/I2fhP0xWFopPy82Rox73hf+EqwzTsOzijxdw== X-Received: by 2002:a1c:800f:: with SMTP id b15mr2850434wmd.114.1601038323513; Fri, 25 Sep 2020 05:52:03 -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 08/19] tools/vhost-user-rpmb: connect to fd and instantiate basic run loop Date: Fri, 25 Sep 2020 13:51:36 +0100 Message-Id: <20200925125147.26943-9-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::344; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x344.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) Again doesn't do much on it's own but will create a socket and wait on messages coming in from the vhost-user message socket. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 211 +++++++++++++++++++++++++++++- tools/vhost-user-rpmb/meson.build | 2 +- 2 files changed, 210 insertions(+), 3 deletions(-) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 6b1989125bd6..269c86cbb633 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -7,10 +7,23 @@ */ =20 #include +#include +#include #include +#include +#include + +#include "contrib/libvhost-user/libvhost-user-glib.h" +#include "contrib/libvhost-user/libvhost-user.h" + +#ifndef container_of +#define container_of(ptr, type, member) ({ \ + const typeof(((type *) 0)->member) *__mptr =3D (ptr); \ + (type *) ((char *) __mptr - offsetof(type, member));}) +#endif =20 static gchar *socket_path; -static gint socket_fd; +static gint socket_fd =3D -1; static gboolean print_cap; =20 static GOptionEntry options[] =3D @@ -21,6 +34,147 @@ static GOptionEntry options[] =3D { NULL } }; =20 +enum { + VHOST_USER_RPMB_MAX_QUEUES =3D 1, +}; + +/* These structures are defined in the specification */ + +struct virtio_rpmb_config { + uint8_t capacity; + uint8_t max_wr_cnt; + uint8_t max_rd_cnt; +}; + +struct virtio_rpmb_frame { + uint8_t stuff[196]; + uint8_t key_mac[32]; + uint8_t data[256]; + uint8_t nonce[16]; + /* remaining fields are big-endian */ + uint32_t write_counter; + uint16_t address; + uint16_t block_count; + uint16_t result; + uint16_t req_resp; +}; + +/* + * Structure to track internal state of RPMB Device + */ + +typedef struct VuRpmb { + VugDev dev; + struct virtio_rpmb_config virtio_config; +} VuRpmb; + +struct virtio_rpmb_ctrl_command { + VuVirtqElement elem; + VuVirtq *vq; + struct virtio_rpmb_frame frame; + uint32_t error; + bool finished; +}; + +static void vrpmb_panic(VuDev *dev, const char *msg) +{ + g_critical("%s\n", msg); + exit(EXIT_FAILURE); +} + +static uint64_t vrpmb_get_features(VuDev *dev) +{ + return 0; +} + +static void vrpmb_set_features(VuDev *dev, uint64_t features) +{ + if (features) { + g_autoptr(GString) s =3D g_string_new("Requested un-handled featur= e"); + g_string_append_printf(s, " 0x%" PRIx64 "", features); + g_info("%s: %s", __func__, s->str); + } +} + +/* + * The configuration of the device is static and set when we start the + * daemon. + */ +static int +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); + return 0; +} + +static int +vrpmb_set_config(VuDev *dev, const uint8_t *data, + uint32_t offset, uint32_t size, + uint32_t flags) +{ + /* ignore */ + return 0; +} + +static void +vrpmb_handle_ctrl(VuDev *dev, int qidx) +{ + VuVirtq *vq =3D vu_get_queue(dev, qidx); + struct virtio_rpmb_ctrl_command *cmd =3D NULL; + + for (;;) { + cmd =3D vu_queue_pop(dev, vq, sizeof(struct virtio_rpmb_ctrl_comma= nd)); + if (!cmd) { + break; + } + + g_debug("un-handled cmd: %p", cmd); + } +} + +static void +vrpmb_queue_set_started(VuDev *dev, int qidx, bool started) +{ + VuVirtq *vq =3D vu_get_queue(dev, qidx); + + g_debug("queue started %d:%d\n", qidx, started); + + switch (qidx) { + case 0: + vu_set_queue_handler(dev, vq, started ? vrpmb_handle_ctrl : NULL); + break; + default: + break; + } +} + +static int +vrpmb_process_msg(VuDev *dev, VhostUserMsg *msg, int *do_reply) +{ + switch (msg->request) { + default: + return 0; + } + + return 0; +} + +static const VuDevIface vuiface =3D { + .set_features =3D vrpmb_set_features, + .get_features =3D vrpmb_get_features, + .queue_set_started =3D vrpmb_queue_set_started, + .process_msg =3D vrpmb_process_msg, + .get_config =3D vrpmb_get_config, + .set_config =3D vrpmb_set_config, +}; + +static void vrpmb_destroy(VuRpmb *r) +{ + vug_deinit(&r->dev); +} + /* Print vhost-user.json backend program capabilities */ static void print_capabilities(void) { @@ -33,8 +187,11 @@ int main (int argc, char *argv[]) { GError *error =3D NULL; GOptionContext *context; + g_autoptr(GMainLoop) loop =3D NULL; + g_autoptr(GSocket) socket =3D NULL; + VuRpmb rpmb =3D { }; =20 - context =3D g_option_context_new ("vhost-user-rpmb - vhost-user emulat= ion of RPBM device"); + context =3D g_option_context_new ("vhost-user emulation of RPBM device= "); g_option_context_add_main_entries (context, options, "vhost-user-rpmb"= ); if (!g_option_context_parse (context, &argc, &argv, &error)) { @@ -47,4 +204,54 @@ int main (int argc, char *argv[]) exit(0); } =20 + if (!socket_path && socket_fd < 0) { + g_printerr("Please specify either --fd or --socket-path\n"); + exit(EXIT_FAILURE); + } + + /* + * Now create a vhost-user socket that we will receive messages + * on. Once we have our handler set up we can enter the glib main + * loop. + */ + if (socket_path) { + g_autoptr(GSocketAddress) addr =3D g_unix_socket_address_new(socke= t_path); + g_autoptr(GSocket) bind_socket =3D g_socket_new(G_SOCKET_FAMILY_UN= IX, G_SOCKET_TYPE_STREAM, + G_SOCKET_PROTOCOL_DE= FAULT, &error); + + if (!g_socket_bind(bind_socket, addr, false, &error)) { + g_printerr("Failed to bind to socket at %s (%s).\n", + socket_path, error->message); + exit(EXIT_FAILURE); + } + if (!g_socket_listen(bind_socket, &error)) { + g_printerr("Failed to listen on socket %s (%s).\n", + socket_path, error->message); + } + g_message("awaiting connection to %s", socket_path); + socket =3D g_socket_accept(bind_socket, NULL, &error); + if (!socket) { + g_printerr("Failed to accept on socket %s (%s).\n", + socket_path, error->message); + } + } else { + socket =3D g_socket_new_from_fd(socket_fd, &error); + if (!socket) { + g_printerr("Failed to connect to FD %d (%s).\n", + socket_fd, error->message); + exit(EXIT_FAILURE); + } + } + + if (!vug_init(&rpmb.dev, VHOST_USER_RPMB_MAX_QUEUES, g_socket_get_fd(s= ocket), + vrpmb_panic, &vuiface)) { + g_printerr("Failed to initialize libvhost-user-glib.\n"); + exit(EXIT_FAILURE); + } + + loop =3D g_main_loop_new(NULL, FALSE); + g_main_loop_run(loop); + g_main_loop_unref(loop); + + vrpmb_destroy(&rpmb); } diff --git a/tools/vhost-user-rpmb/meson.build b/tools/vhost-user-rpmb/meso= n.build index e0df1b69a3fb..cf80bedd99ac 100644 --- a/tools/vhost-user-rpmb/meson.build +++ b/tools/vhost-user-rpmb/meson.build @@ -1,6 +1,6 @@ executable('vhost-user-rpmb', files( 'main.c'), - dependencies: [glib], + dependencies: [qemuutil, glib, gio], link_with: [libvhost_user], install: true, install_dir: get_option('libexecdir')) --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038654; cv=none; d=zohomail.com; s=zohoarc; b=PKU1AGOSIo6CfmDQnZsTC7E0/CbSqm/ifaBPtO/6PUaegyZ+l7fcDTjLq5Gcn9gFPiD9AK9ONmiDMDoFVaL/MIPJgl4k+0sCQUxXKvAWmJ1iC8OOLIdSqBmH3uSjeDnuc3Vk93N9cKveV5FKqBUxeLWbtM4/I9lJthNpKG7GPxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038654; 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=DYHqy58UJZR46wXpvs59hJagcJIqgUuvxLRDNUapKkI=; b=hZVeyi/F1JOCSRT3u37HuknjLff+cZUhuj6xb6nK1hO0eIqXt3po1mo887C2vAsXqbbmrpKyyHDY7NBHXZldOkOEpKmIvXKrTdYmVx3d5iits/5oUkIOoK5szQ6Y2Ak+7AaqSrMVkD+fUD7BGpuss7Oz9vYBn6aZlExGIlJviZA= 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 1601038654512571.5104935616994; Fri, 25 Sep 2020 05:57:34 -0700 (PDT) Received: from localhost ([::1]:53496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnI5-00070L-5t for importer@patchew.org; Fri, 25 Sep 2020 08:57:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48284) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCs-0007o4-Cs for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:10 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:39623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCq-0001Ql-8P for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:10 -0400 Received: by mail-wm1-x343.google.com with SMTP id b79so3165742wmb.4 for ; Fri, 25 Sep 2020 05:52:07 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id m12sm2708543wml.38.2020.09.25.05.51.54 (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 173971FF98; 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=DYHqy58UJZR46wXpvs59hJagcJIqgUuvxLRDNUapKkI=; b=PLLxusxhPFqPGcofHMPBU7+IrVX7cQrLqgbuFwawPTVl20xOtV1nU3phv+B+iZ4AHa g6keJCPtstcNtkR9uvaZR6JJFaC+CjknldAUPdPCKsKEqqQdWg7LQ/K64hl5HabyR+I2 XSZC8zZAAoQbmjDZS9YNLV94KZuLi3xRHX0VLG/Fck6PAhVxCTdnu5nWkj+h3JthSgFt /DM5h3kfoW2vgHw+PVqreYUPDkb5qTvo2xXHv7fcmFtCsNdZ/1Wv5+Bqip7AwK31O8Vt TwzJnYZQXcWYdG2MOygKPCTZz2aVxUEYC/IWxxydBRUNyRiC7pnfkoDkJoL/Yb8CwfVz LUDw== 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=DYHqy58UJZR46wXpvs59hJagcJIqgUuvxLRDNUapKkI=; b=qauUn9YTiIZ29QaG9zlffh9DQEymYDQXh5lXJbjJFnEZ25SE5F+2XKDoMFo8rMA9nj xDN5TmbEdmn34c8yJaUK7AsBM53xX2llnqHlkHZK+dN5oRblrprgpBexm+QcWYSd2367 WmYPk7EfKLGqkt69lD2h3lNQKV2aQe/s0HQJ7izseufxSUulVJGItfgjbjlKh/yyV+ra 3ktswvQkZZaC1WZI2limO8TXtCW/fLvVCNIkGe7K67n7giE3rJgPDVK3q8TlwAIsxQQP RZvKGjs2hx1WVVraK758DwyUbLDDqaRcd0bea2AOE6Lzd6EzjIo6/dhSH6+6eko7kqsq jrkw== X-Gm-Message-State: AOAM533VbynN63xu/oKej6wX15RxLYT7HHBqItYw0pRsPHEVxrwZduBg sK83FWepZM5jL+TvZWzI6MeaYw== X-Google-Smtp-Source: ABdhPJzzqmM6H2FagwjjJuJz8oyzXp/4kjhdAn5abuNmGND89rNn/daHMZEIYFS4dnMv23kcecepaA== X-Received: by 2002:a1c:4455:: with SMTP id r82mr2957959wma.60.1601038326726; Fri, 25 Sep 2020 05:52:06 -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 09/19] tools/vhost-user-rpmb: add a --verbose/debug flags for logging Date: Fri, 25 Sep 2020 13:51:37 +0100 Message-Id: <20200925125147.26943-10-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::343; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x343.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) This gives us two levels of informational output when tracing what the daemon is doing. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 269c86cbb633..1be0d4b8a567 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -6,6 +6,9 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 +#define G_LOG_DOMAIN "vhost-user-rpmb" +#define G_LOG_USE_STRUCTURED 1 + #include #include #include @@ -25,12 +28,16 @@ static gchar *socket_path; static gint socket_fd =3D -1; static gboolean print_cap; +static gboolean verbose; +static gboolean debug; =20 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" }, { "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}, + { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Include debug output", NU= LL}, { NULL } }; =20 @@ -84,6 +91,7 @@ static void vrpmb_panic(VuDev *dev, const char *msg) =20 static uint64_t vrpmb_get_features(VuDev *dev) { + g_info("%s: replying", __func__); return 0; } =20 @@ -209,6 +217,17 @@ int main (int argc, char *argv[]) exit(EXIT_FAILURE); } =20 + if (verbose || debug) { + g_log_set_handler(NULL, G_LOG_LEVEL_MASK, g_log_default_handler, N= ULL); + if (debug) { + g_setenv("G_MESSAGES_DEBUG", "all", true); + } + } else { + g_log_set_handler(NULL, + G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_L= OG_LEVEL_ERROR, + g_log_default_handler, NULL); + } + /* * Now create a vhost-user socket that we will receive messages * on. Once we have our handler set up we can enter the glib main --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038743; cv=none; d=zohomail.com; s=zohoarc; b=YwPnsD3MoYEszWMqJMjdBOONQgYGz0z7bjAkk+EO1QT/nIpg/krRxVq07VyHgJXTitOCf844hBtL9kuBS0ouoznp0bd7mAF5BDF4ebonQya61Oihl8tFOCBOApMy3OizeF5kyhgs7wClQNXauovEmIf78qH/+MCoV81thJrNOoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038743; 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=La3wf0jgdLLaxy3qyiZ5nLFWQDulF/WBD+D4LgHv5vo=; b=h0AyrXdUf6mER3ZkU9VZ63TsqKLODLWZGGvpEjKr+v25qxTCDgeeJqJliNFpxd24Ej3C/W93vKxroTieRcvEG5f+cctSLm8nI8jQOq4WhoOk34rLqDENEuYl4SqPDnJuD0xND1XpXVfoKNTZmWCbhH3i3ffg32K8hF+c5sDtnJA= 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 160103874352532.365151070352454; Fri, 25 Sep 2020 05:59:03 -0700 (PDT) Received: from localhost ([::1]:32840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnJW-0001eZ-7f for importer@patchew.org; Fri, 25 Sep 2020 08:59:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCu-0007qm-Eh for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:13 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:34820) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCs-0001R5-EM for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:12 -0400 Received: by mail-wr1-x444.google.com with SMTP id e16so3518664wrm.2 for ; Fri, 25 Sep 2020 05:52:10 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id i83sm2877331wma.22.2020.09.25.05.51.54 (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 2C74D1FF99; 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=La3wf0jgdLLaxy3qyiZ5nLFWQDulF/WBD+D4LgHv5vo=; b=gDSOYgSFewYCKCeiBthgQfO9lDdu251R/GVGuV69QTfKwahNlWXaTyMUnKiZcCLRwZ J3We7jodc6NQ7jHC86IJpHHURJc45O+bvnnqI/MehiicHpvvWUHzonrCKxc14M1htnM/ ieM+uPWUdkfYbyHoEGQ0NqHWnjG2MmAr6amBossVDArsXaThqA69zcMqZjL29V/xRPkG kQHSWh0RGM5Ot/o7V6ISt5Uk//+IctUG0nsjkBfnJ8HUfN9mJvW0hGc0oHrppjAB3Gyr 4qJxETzaACuIVtVWHItKkcHuifPd/KG7nyqc8SFS3PCAQDKiG1gnlCzGoa6FpimLafIb 6DlQ== 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=La3wf0jgdLLaxy3qyiZ5nLFWQDulF/WBD+D4LgHv5vo=; b=ebZ5YeV1lRoi66VlnEZ71ngjmuGPxV3rKcY7L9JYfagjjasow/bX/jANw85LfaVUmp sE4AkQnCzOSpGWOtknIC/GoreIXhU6b/SWwz8NrTBgxd680jX59T56v7voJ3GiPpKScB wCTrDrGmTTVFjm9uaDGk0bOyHTCdbH65I3GtOAM/fq8AWJBPLs5ehxGrTREQnzHvoIqf Rrh7hQNGmVWD0Hrlnp+mP+KGdHKg2Xjck6FzZmNYqCxzOcgrPrPj5CIVkG/W6cdlEZs7 tvAL7sdDHJzOIJtzFNpZZIKJiR3xNyo5WyROYQpIue+oRYArXS2a0xx5Oej+Y8PgYwsY FtDQ== X-Gm-Message-State: AOAM530WE1A75FXBMUm1cgdQqXnNXRA9HSp6TtkwAVJdrCF0wbPba5bu zRV+/3b0FfhrvSlK/75XYZDiYg== X-Google-Smtp-Source: ABdhPJw+FnAq0jAiugV2Cg4Tl3jIA4VQwRsQf9Hp7qNWdz8GCxcD2vXGq4F6xrTrZ0uReMSF0qA0HQ== X-Received: by 2002:adf:e292:: with SMTP id v18mr4351820wri.256.1601038329141; Fri, 25 Sep 2020 05:52:09 -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 10/19] tools/vhost-user-rpmb: handle shutdown and SIGINT/SIGHUP cleanly Date: Fri, 25 Sep 2020 13:51:38 +0100 Message-Id: <20200925125147.26943-11-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::444; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x444.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) The libvhost-user library will just exit if it handles the VHOST_USER_NONE message and we want to ensure we have tidied up after ourselves. As we need to signal the shutdown of the main loop we need to move the information into the VuRmb state structure. We also want to do the same if we catch a SIGINT/SIGHUP termination signal. While we are at it add some instrumentation so we can follow the program flow. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 49 +++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 1be0d4b8a567..7b3b29ccfc5b 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -73,6 +74,7 @@ struct virtio_rpmb_frame { typedef struct VuRpmb { VugDev dev; struct virtio_rpmb_config virtio_config; + GMainLoop *loop; } VuRpmb; =20 struct virtio_rpmb_ctrl_command { @@ -158,10 +160,22 @@ vrpmb_queue_set_started(VuDev *dev, int qidx, bool st= arted) } } =20 -static int -vrpmb_process_msg(VuDev *dev, VhostUserMsg *msg, int *do_reply) +/* + * vrpmb_process_msg: process messages of vhost-user interface + * + * Any that are not handled here are processed by the libvhost library + * itself. + */ +static int vrpmb_process_msg(VuDev *dev, VhostUserMsg *msg, int *do_reply) { + VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); + + g_info("%s: msg %d", __func__, msg->request); + switch (msg->request) { + case VHOST_USER_NONE: + g_main_loop_quit(r->loop); + return 1; default: return 0; } @@ -181,6 +195,9 @@ static const VuDevIface vuiface =3D { static void vrpmb_destroy(VuRpmb *r) { vug_deinit(&r->dev); + if (socket_path) { + unlink(socket_path); + } } =20 /* Print vhost-user.json backend program capabilities */ @@ -191,11 +208,18 @@ static void print_capabilities(void) printf("}\n"); } =20 +static gboolean hangup(gpointer user_data) +{ + GMainLoop *loop =3D (GMainLoop *) user_data; + g_info("%s: caught hangup/quit signal, quitting main loop", __func__); + g_main_loop_quit(loop); + return true; +} + int main (int argc, char *argv[]) { GError *error =3D NULL; GOptionContext *context; - g_autoptr(GMainLoop) loop =3D NULL; g_autoptr(GSocket) socket =3D NULL; VuRpmb rpmb =3D { }; =20 @@ -262,15 +286,28 @@ int main (int argc, char *argv[]) } } =20 + /* + * Create the main loop first so all the various sources can be + * added. As well as catching signals we need to ensure vug_init + * can add it's GSource watches. + */ + + rpmb.loop =3D g_main_loop_new(NULL, FALSE); + /* catch exit signals */ + g_unix_signal_add(SIGHUP, hangup, rpmb.loop); + g_unix_signal_add(SIGINT, hangup, rpmb.loop); + if (!vug_init(&rpmb.dev, VHOST_USER_RPMB_MAX_QUEUES, g_socket_get_fd(s= ocket), vrpmb_panic, &vuiface)) { g_printerr("Failed to initialize libvhost-user-glib.\n"); exit(EXIT_FAILURE); } =20 - loop =3D g_main_loop_new(NULL, FALSE); - g_main_loop_run(loop); - g_main_loop_unref(loop); =20 + g_message("entering main loop, awaiting messages"); + g_main_loop_run(rpmb.loop); + g_message("finished main loop, cleaning up"); + + g_main_loop_unref(rpmb.loop); vrpmb_destroy(&rpmb); } --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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 From nobody Thu Apr 25 14:33:28 2024 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=1601039015; cv=none; d=zohomail.com; s=zohoarc; b=c0uhTFKWeSFZ93tNw1kTa5VnUVbVbDZbQaHKEY/UOq30v05Jrauc1x1cnf98UTYuzTTLSNFiHTQuhJynj+VI83OJvbAr8/8DQv3XZ30mHOn24rYqWZJUYRY+JuxSa80CQKKEspsN4EOjyun74jfDWmuv8mADEXOuugFg+SNwWgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601039015; 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=2gc/eAiM6fc/9xFq9v+gXHzceFFWcZXTxfGGQdY3TKo=; b=mMMRqAKeyvEniadhgue2EdsSIm+Rw2TCFdTNhp3RuE51h5U3fwjkwzbxT2flV+2nDaKaDfmwtrkKLO+rbWq60gy6kYfWQfrOEyJaateufXLFpa63fem2IOl+oe22WDHyNAaP2ICz0JE9CA84s1gJHmXIn6ucZdVhMe+IZuGlTqs= 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 1601039015766225.40163059794054; Fri, 25 Sep 2020 06:03:35 -0700 (PDT) Received: from localhost ([::1]:40578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnNp-00054f-Kj for importer@patchew.org; Fri, 25 Sep 2020 09:03:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnCw-0007rp-Si for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:14 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]:53738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnCu-0001RU-3c for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:52:14 -0400 Received: by mail-wm1-x32d.google.com with SMTP id x23so2927646wmi.3 for ; Fri, 25 Sep 2020 05:52:11 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l126sm2849103wmf.39.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 5E0241FF9B; 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=2gc/eAiM6fc/9xFq9v+gXHzceFFWcZXTxfGGQdY3TKo=; b=lL+PE4Xcu99+Yf301fWBDOYOKBRFX4BGFnZJ9UM7e6YQx7nI3w4CwXaBrlDtW24dA7 9yH0LGCvLuy+6BePjaLK1Vg1wGGk81aoyFSpUs2ZOC/clFHjzRFJ5XlSSO7/i7x/vkjN g0roGJSrbKQve6pS7JsMrp+kDyc9YYHw+3/f04F6DOnoJ1nQpXYmGJDG/RvPf7xuxmx7 ouVpX/eJImiwkjssNy4cVXCMVUjntSt3ydwH8eVazGioYkm5+7tClPR79hX3PJa1G9Od Mm7sOQrVgX+nxEgdIFkHH8pbG3IUlI2fURFwA6jXVZzmfqpo/yNQtoPA9PVNEdHPHoJs BbsQ== 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=2gc/eAiM6fc/9xFq9v+gXHzceFFWcZXTxfGGQdY3TKo=; b=LshQ5juMAg9NyBcvAzw9yzFSmq2/V0jMfbU5YNUHcolFJZR01niF3Kz1BSh5ixc1nG 4eyFWvpbX9G70CyxlLv4R6VtnwIGMz5F8KCO7948gUUomUmg4GBscHKE6His/pymbEV3 KvhqD8rAoedPk9gBu3b5UtzpxpQyQPykh16z8BNtHtCCJOycV7e/PLbe/S1vzwWerJ8u yIS1BPU3lWYoS105pg9qD3fo4hxyg2JyMZFqWxFt8ir5Z/yjsat3kiTtmErLQmWo22vw b1rtbN/uxKCJ1taHjelDreDv7LbRqJzxTTSQ1+hjlmyzuVVtE/w2PmMvWBihNV42iFNg z3lw== X-Gm-Message-State: AOAM530TMNHFRgFENs7DMb/20lmht/UnBPUu/l1P2jKA2cZoDyzw/fxP CumPgkMLP+zqfY/rXrr8m71lhg== X-Google-Smtp-Source: ABdhPJxeBSupo8i5C6YvM07AtjMhDiqQ1xpAwpiJVWc7s3N20uU84fMRZW1sEDeRezUSSYo0TsiUYQ== X-Received: by 2002:a1c:ed19:: with SMTP id l25mr3025751wmh.49.1601038330538; Fri, 25 Sep 2020 05:52:10 -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 12/19] tools/vhost-user-rpmb: import hmac_sha256 functions Date: Fri, 25 Sep 2020 13:51:40 +0100 Message-Id: <20200925125147.26943-13-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::32d; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32d.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 need to calculate HMAC-256SHA as part of the protocol. To avoid making the daemon dependent on QEMU's internal crypto library we import the functions here. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/hmac_sha256.h | 87 ++++++++ tools/vhost-user-rpmb/hmac_sha256.c | 331 ++++++++++++++++++++++++++++ tools/vhost-user-rpmb/meson.build | 3 +- 3 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 tools/vhost-user-rpmb/hmac_sha256.h create mode 100644 tools/vhost-user-rpmb/hmac_sha256.c diff --git a/tools/vhost-user-rpmb/hmac_sha256.h b/tools/vhost-user-rpmb/hm= ac_sha256.h new file mode 100644 index 000000000000..e67a5baedecd --- /dev/null +++ b/tools/vhost-user-rpmb/hmac_sha256.h @@ -0,0 +1,87 @@ +/* + * HMAC-SHA-256 implementation + * Last update: 06/15/2005 + * Issue date: 06/15/2005 + * + * Copyright (C) 2005 Olivier Gay + * All rights reserved. + * + * Copyright (c) 2016, 2020, Linaro Limited + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef HMAC_SHA256_H +#define HMAC_SHA256_H + +#define SHA256_DIGEST_SIZE ( 256 / 8) +#define SHA256_BLOCK_SIZE ( 512 / 8) + +#ifndef SHA2_TYPES +#define SHA2_TYPES +typedef unsigned char uint8; +typedef unsigned int uint32; +typedef unsigned long long uint64; +#endif + +typedef struct { + unsigned int tot_len; + unsigned int len; + unsigned char block[2 * SHA256_BLOCK_SIZE]; + uint32 h[8]; +} sha256_ctx; + +void sha256_init(sha256_ctx * ctx); +void sha256_update(sha256_ctx *ctx, const unsigned char *message, + unsigned int len); +void sha256_final(sha256_ctx *ctx, unsigned char *digest); +void sha256(const unsigned char *message, unsigned int len, + unsigned char *digest); + +typedef struct { + sha256_ctx ctx_inside; + sha256_ctx ctx_outside; + + /* for hmac_reinit */ + sha256_ctx ctx_inside_reinit; + sha256_ctx ctx_outside_reinit; + + unsigned char block_ipad[SHA256_BLOCK_SIZE]; + unsigned char block_opad[SHA256_BLOCK_SIZE]; +} hmac_sha256_ctx; + +void hmac_sha256_init(hmac_sha256_ctx *ctx, const unsigned char *key, + unsigned int key_size); +void hmac_sha256_reinit(hmac_sha256_ctx *ctx); +void hmac_sha256_update(hmac_sha256_ctx *ctx, const unsigned char *message, + unsigned int message_len); +void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac, + unsigned int mac_size); +void hmac_sha256(const unsigned char *key, unsigned int key_size, + const unsigned char *message, unsigned int message_len, + unsigned char *mac, unsigned mac_size); + +#endif /* !HMAC_SHA256_H */ diff --git a/tools/vhost-user-rpmb/hmac_sha256.c b/tools/vhost-user-rpmb/hm= ac_sha256.c new file mode 100644 index 000000000000..f6640a46c616 --- /dev/null +++ b/tools/vhost-user-rpmb/hmac_sha256.c @@ -0,0 +1,331 @@ +/* + * HMAC-SHA-256 implementation + * Last update: 06/15/2005 + * Issue date: 06/15/2005 + * + * Copyright (C) 2005 Olivier Gay + * All rights reserved. + * + * Copyright (c) 2016, 2020 Linaro Limited + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT= IAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR= ICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W= AY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include "hmac_sha256.h" + +/* SHA256 functions */ + +#define SHFR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) +#define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) +#define CH(x, y, z) ((x & y) ^ (~x & z)) +#define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) + +#define SHA256_F1(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define SHA256_F2(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3)) +#define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10)) + +#define UNPACK32(x, str) \ +{ \ + *((str) + 3) =3D (uint8) ((x) ); \ + *((str) + 2) =3D (uint8) ((x) >> 8); \ + *((str) + 1) =3D (uint8) ((x) >> 16); \ + *((str) + 0) =3D (uint8) ((x) >> 24); \ +} + +#define PACK32(str, x) \ +{ \ + *(x) =3D ((uint32) *((str) + 3) ) \ + | ((uint32) *((str) + 2) << 8) \ + | ((uint32) *((str) + 1) << 16) \ + | ((uint32) *((str) + 0) << 24); \ +} + +#define UNPACK64(x, str) \ +{ \ + *((str) + 7) =3D (uint8) ((x) ); \ + *((str) + 6) =3D (uint8) ((x) >> 8); \ + *((str) + 5) =3D (uint8) ((x) >> 16); \ + *((str) + 4) =3D (uint8) ((x) >> 24); \ + *((str) + 3) =3D (uint8) ((x) >> 32); \ + *((str) + 2) =3D (uint8) ((x) >> 40); \ + *((str) + 1) =3D (uint8) ((x) >> 48); \ + *((str) + 0) =3D (uint8) ((x) >> 56); \ +} + +#define PACK64(str, x) \ +{ \ + *(x) =3D ((uint64) *((str) + 7) ) \ + | ((uint64) *((str) + 6) << 8) \ + | ((uint64) *((str) + 5) << 16) \ + | ((uint64) *((str) + 4) << 24) \ + | ((uint64) *((str) + 3) << 32) \ + | ((uint64) *((str) + 2) << 40) \ + | ((uint64) *((str) + 1) << 48) \ + | ((uint64) *((str) + 0) << 56); \ +} + +#define SHA256_SCR(i) \ +{ \ + w[i] =3D SHA256_F4(w[i - 2]) + w[i - 7] \ + + SHA256_F3(w[i - 15]) + w[i - 16]; \ +} + +uint32 sha256_h0[8] =3D + {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; + +uint32 sha256_k[64] =3D + {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; + +/* SHA-256 functions */ + +static void sha256_transf(sha256_ctx *ctx, const unsigned char *message, + unsigned int block_nb) +{ + uint32 w[64]; + uint32 wv[8]; + uint32 t1, t2; + const unsigned char *sub_block; + int i; + int j; + + for (i =3D 0; i < (int) block_nb; i++) { + sub_block =3D message + (i << 6); + + for (j =3D 0; j < 16; j++) { + PACK32(&sub_block[j << 2], &w[j]); + } + + for (j =3D 16; j < 64; j++) { + SHA256_SCR(j); + } + + for (j =3D 0; j < 8; j++) { + wv[j] =3D ctx->h[j]; + } + + for (j =3D 0; j < 64; j++) { + t1 =3D wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + + sha256_k[j] + w[j]; + t2 =3D SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); + wv[7] =3D wv[6]; + wv[6] =3D wv[5]; + wv[5] =3D wv[4]; + wv[4] =3D wv[3] + t1; + wv[3] =3D wv[2]; + wv[2] =3D wv[1]; + wv[1] =3D wv[0]; + wv[0] =3D t1 + t2; + } + + for (j =3D 0; j < 8; j++) { + ctx->h[j] +=3D wv[j]; + } + } +} + +void sha256(const unsigned char *message, unsigned int len, unsigned char = *digest) +{ + sha256_ctx ctx; + + sha256_init(&ctx); + sha256_update(&ctx, message, len); + sha256_final(&ctx, digest); +} + +void sha256_init(sha256_ctx *ctx) +{ + int i; + for (i =3D 0; i < 8; i++) { + ctx->h[i] =3D sha256_h0[i]; + } + + ctx->len =3D 0; + ctx->tot_len =3D 0; +} + +void sha256_update(sha256_ctx *ctx, const unsigned char *message, + unsigned int len) +{ + unsigned int block_nb; + unsigned int new_len, rem_len, tmp_len; + const unsigned char *shifted_message; + + tmp_len =3D SHA256_BLOCK_SIZE - ctx->len; + rem_len =3D len < tmp_len ? len : tmp_len; + + memcpy(&ctx->block[ctx->len], message, rem_len); + + if (ctx->len + len < SHA256_BLOCK_SIZE) { + ctx->len +=3D len; + return; + } + + new_len =3D len - rem_len; + block_nb =3D new_len / SHA256_BLOCK_SIZE; + + shifted_message =3D message + rem_len; + + sha256_transf(ctx, ctx->block, 1); + sha256_transf(ctx, shifted_message, block_nb); + + rem_len =3D new_len % SHA256_BLOCK_SIZE; + + memcpy(ctx->block, &shifted_message[block_nb << 6], + rem_len); + + ctx->len =3D rem_len; + ctx->tot_len +=3D (block_nb + 1) << 6; +} + +void sha256_final(sha256_ctx *ctx, unsigned char *digest) +{ + unsigned int block_nb; + unsigned int pm_len; + unsigned int len_b; + int i; + + block_nb =3D (1 + ((SHA256_BLOCK_SIZE - 9) + < (ctx->len % SHA256_BLOCK_SIZE))); + + len_b =3D (ctx->tot_len + ctx->len) << 3; + pm_len =3D block_nb << 6; + + memset(ctx->block + ctx->len, 0, pm_len - ctx->len); + ctx->block[ctx->len] =3D 0x80; + UNPACK32(len_b, ctx->block + pm_len - 4); + + sha256_transf(ctx, ctx->block, block_nb); + + for (i =3D 0 ; i < 8; i++) { + UNPACK32(ctx->h[i], &digest[i << 2]); + } +} + +/* HMAC-SHA-256 functions */ + +void hmac_sha256_init(hmac_sha256_ctx *ctx, const unsigned char *key, + unsigned int key_size) +{ + unsigned int fill; + unsigned int num; + + const unsigned char *key_used; + unsigned char key_temp[SHA256_DIGEST_SIZE]; + int i; + + if (key_size =3D=3D SHA256_BLOCK_SIZE) { + key_used =3D key; + num =3D SHA256_BLOCK_SIZE; + } else { + if (key_size > SHA256_BLOCK_SIZE){ + num =3D SHA256_DIGEST_SIZE; + sha256(key, key_size, key_temp); + key_used =3D key_temp; + } else { /* key_size > SHA256_BLOCK_SIZE */ + key_used =3D key; + num =3D key_size; + } + fill =3D SHA256_BLOCK_SIZE - num; + + memset(ctx->block_ipad + num, 0x36, fill); + memset(ctx->block_opad + num, 0x5c, fill); + } + + for (i =3D 0; i < (int) num; i++) { + ctx->block_ipad[i] =3D key_used[i] ^ 0x36; + ctx->block_opad[i] =3D key_used[i] ^ 0x5c; + } + + sha256_init(&ctx->ctx_inside); + sha256_update(&ctx->ctx_inside, ctx->block_ipad, SHA256_BLOCK_SIZE); + + sha256_init(&ctx->ctx_outside); + sha256_update(&ctx->ctx_outside, ctx->block_opad, + SHA256_BLOCK_SIZE); + + /* for hmac_reinit */ + memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, + sizeof(sha256_ctx)); + memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, + sizeof(sha256_ctx)); +} + +void hmac_sha256_reinit(hmac_sha256_ctx *ctx) +{ + memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, + sizeof(sha256_ctx)); + memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, + sizeof(sha256_ctx)); +} + +void hmac_sha256_update(hmac_sha256_ctx *ctx, const unsigned char *message, + unsigned int message_len) +{ + sha256_update(&ctx->ctx_inside, message, message_len); +} + +void hmac_sha256_final(hmac_sha256_ctx *ctx, unsigned char *mac, + unsigned int mac_size) +{ + unsigned char digest_inside[SHA256_DIGEST_SIZE]; + unsigned char mac_temp[SHA256_DIGEST_SIZE]; + + sha256_final(&ctx->ctx_inside, digest_inside); + sha256_update(&ctx->ctx_outside, digest_inside, SHA256_DIGEST_SIZE); + sha256_final(&ctx->ctx_outside, mac_temp); + memcpy(mac, mac_temp, mac_size); +} + +void hmac_sha256(const unsigned char *key, unsigned int key_size, + const unsigned char *message, unsigned int message_len, + unsigned char *mac, unsigned mac_size) +{ + hmac_sha256_ctx ctx; + + hmac_sha256_init(&ctx, key, key_size); + hmac_sha256_update(&ctx, message, message_len); + hmac_sha256_final(&ctx, mac, mac_size); +} diff --git a/tools/vhost-user-rpmb/meson.build b/tools/vhost-user-rpmb/meso= n.build index cf80bedd99ac..f964837d151d 100644 --- a/tools/vhost-user-rpmb/meson.build +++ b/tools/vhost-user-rpmb/meson.build @@ -1,5 +1,6 @@ executable('vhost-user-rpmb', files( - 'main.c'), + 'main.c', + 'hmac_sha256.c'), dependencies: [qemuutil, glib, gio], link_with: [libvhost_user], install: true, --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601039336; cv=none; d=zohomail.com; s=zohoarc; b=JFVb+WCHozYMFMcG4ZB4NJ7O9Ruxjix+hel8puZZNX2baflQFr52Sx5VX1Eb6uzVx+IFXorb728gQzhGdTtK3131WGR7gsuUL3X6+8V1RB02Q1GVHQhSPCDqoCToaUXmIiYH5Z2ZbNQoypYxBQoKGycjJLZnpGp5BABrR8IBf3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601039336; 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=Q4iTHSBorxk55Li2+GvTNnYqx3kRUnXXkY6aAFMYM/s=; b=GZ4yJ7CWmpEZ38EmDBiKIC/CCG3uMQnqYDywJ57JIhOfIfz86iqPyzg/VuS/grniA9at10VqK2mw1xRTA2nHhE9OKpla+9L9gDtDvctoErLkywJhBiwZtZ1Pvp81UQ1Vhl8YoyiVZhSJ1efWBanuNpzBXOr5nL55/mcNnb+Ltlw= 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 1601039336108625.4844150406497; Fri, 25 Sep 2020 06:08:56 -0700 (PDT) Received: from localhost ([::1]:55202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnT4-0003A5-GR for importer@patchew.org; Fri, 25 Sep 2020 09:08:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnJl-0002c8-2W for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:17 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:43772) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnJi-0002HJ-9c for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:16 -0400 Received: by mail-wr1-x442.google.com with SMTP id k15so3471710wrn.10 for ; Fri, 25 Sep 2020 05:59:12 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id x67sm2411242wmb.25.2020.09.25.05.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:59:10 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 74C251FF9C; 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=Q4iTHSBorxk55Li2+GvTNnYqx3kRUnXXkY6aAFMYM/s=; b=v2rf8a22kBUgvdat3avWZaW4mN0N/9L+GeS8rZBwFpbXgyNEA8VuJfT+y6TXOJi/jn 8771/fqeQCE4KnqcuWbyEHsU1A1oyvnct5X0a7zqa6y+v5zKAfikbc6M5TtDu3Vv9KDn eCzpC+XQnacfBUplYEg6WMnBxG+69iasXx9vAWv6aJzUxGNRpuw8gcDthchF1kMwSM7U +4I+PcinNdi8sBnAG4CS1BVzAXnyOcYRp3hzoTca3/k8gTUvmMEW9z5dLqfC8mEs0q2A 2Pfp/TqleOQeL0aOB3Zudp1/B7yTNGO+dN4xcrtnA4CSXUnByPuIBdItaMWf+XqlVdw2 2M9A== 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=Q4iTHSBorxk55Li2+GvTNnYqx3kRUnXXkY6aAFMYM/s=; b=L7GmZS+C3H3uvPVYQimvOMHe3ftMEf+yW26QcMxW8Re+jAWjdpAxurPAM+NM0r2aSJ D3wLvy9Fs5KCeQ9MVhl2jOLj9mqi8ZPup9A+l3Kj7HHndGNgR9GXlRbl5UsQvoXR9rhF KiXip53aks1ipXoOAzlPgZ54G4UaKr8GMoECBSV2c+tx7xhjNBWhTtUu7uilIhcXgONU fiCMrrMQ6TGVPmKUHFjBRuuMkLRPxX+kCYgxlrfCXBhV0XOgu7Ou0WLlDctpC8F2cfQy kQwBx6GYgaVPdoP5KheEAcaDds+6cGrfZrIkvljAAxYDlFu/r3t5Jve+gZNbMOQZyh41 GgvA== X-Gm-Message-State: AOAM5328RgF1ZSOQ0qiI5cE1/GyCEYCJ6ddaUnZs5ysUvIyL+8rN3T7q BEMAULICouFmKfUzf/UhsDDoYA== X-Google-Smtp-Source: ABdhPJyhV2HYYzu/SbmGq+HXq0mlohFIVNFo6iMDNOdcQsYjpYH/oS8OWnIeoRhAoMBBlvixP+sFWw== X-Received: by 2002:a5d:40cd:: with SMTP id b13mr4353786wrq.297.1601038751867; Fri, 25 Sep 2020 05:59:11 -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 13/19] tools/vhost-user-rpmb: implement the PROGRAM_KEY handshake Date: Fri, 25 Sep 2020 13:51:41 +0100 Message-Id: <20200925125147.26943-14-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::442; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x442.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) This implements the first handshake of the device initialisation which is the programming of the device key. This can only be done once per-device. Currently there is no persistence for the device key and other metadata such as the write count. This will be added later. [TODO: clarify the spec if we should respond immediately or on request] Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 299 +++++++++++++++++++++++++++++++++-- 1 file changed, 286 insertions(+), 13 deletions(-) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 64bd7e79f573..9c98f6916f6f 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -22,10 +22,14 @@ #include #include #include +#include +#include =20 #include "contrib/libvhost-user/libvhost-user-glib.h" #include "contrib/libvhost-user/libvhost-user.h" =20 +#include "hmac_sha256.h" + #ifndef container_of #define container_of(ptr, type, member) ({ \ const typeof(((type *) 0)->member) *__mptr =3D (ptr); \ @@ -57,6 +61,31 @@ enum { /* These structures are defined in the specification */ #define KiB (1UL << 10) #define MAX_RPMB_SIZE (KiB * 128 * 256) +#define RPMB_KEY_MAC_SIZE 32 + +/* RPMB Request Types */ +#define VIRTIO_RPMB_REQ_PROGRAM_KEY 0x0001 +#define VIRTIO_RPMB_REQ_GET_WRITE_COUNTER 0x0002 +#define VIRTIO_RPMB_REQ_DATA_WRITE 0x0003 +#define VIRTIO_RPMB_REQ_DATA_READ 0x0004 +#define VIRTIO_RPMB_REQ_RESULT_READ 0x0005 + +/* RPMB Response Types */ +#define VIRTIO_RPMB_RESP_PROGRAM_KEY 0x0100 +#define VIRTIO_RPMB_RESP_GET_COUNTER 0x0200 +#define VIRTIO_RPMB_RESP_DATA_WRITE 0x0300 +#define VIRTIO_RPMB_RESP_DATA_READ 0x0400 + +/* RPMB Operation Results */ +#define VIRTIO_RPMB_RES_OK 0x0000 +#define VIRTIO_RPMB_RES_GENERAL_FAILURE 0x0001 +#define VIRTIO_RPMB_RES_AUTH_FAILURE 0x0002 +#define VIRTIO_RPMB_RES_COUNT_FAILURE 0x0003 +#define VIRTIO_RPMB_RES_ADDR_FAILURE 0x0004 +#define VIRTIO_RPMB_RES_WRITE_FAILURE 0x0005 +#define VIRTIO_RPMB_RES_READ_FAILURE 0x0006 +#define VIRTIO_RPMB_RES_NO_AUTH_KEY 0x0007 +#define VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED 0x0080 =20 struct virtio_rpmb_config { uint8_t capacity; @@ -64,9 +93,13 @@ struct virtio_rpmb_config { uint8_t max_rd_cnt; }; =20 +/* + * This is based on the JDEC standard and not the currently not + * up-streamed NVME standard. + */ struct virtio_rpmb_frame { uint8_t stuff[196]; - uint8_t key_mac[32]; + uint8_t key_mac[RPMB_KEY_MAC_SIZE]; uint8_t data[256]; uint8_t nonce[16]; /* remaining fields are big-endian */ @@ -75,7 +108,7 @@ struct virtio_rpmb_frame { uint16_t block_count; uint16_t result; uint16_t req_resp; -}; +} __attribute__((packed)); =20 /* * Structure to track internal state of RPMB Device @@ -87,15 +120,63 @@ typedef struct VuRpmb { GMainLoop *loop; int flash_fd; void *flash_map; + uint8_t *key; + uint16_t last_result; + uint16_t last_reqresp; } VuRpmb; =20 -struct virtio_rpmb_ctrl_command { - VuVirtqElement elem; - VuVirtq *vq; - struct virtio_rpmb_frame frame; - uint32_t error; - bool finished; -}; +/* refer to util/iov.c */ +static size_t vrpmb_iov_size(const struct iovec *iov, + const unsigned int iov_cnt) +{ + size_t len; + unsigned int i; + + len =3D 0; + for (i =3D 0; i < iov_cnt; i++) { + len +=3D iov[i].iov_len; + } + return len; +} + + +static size_t vrpmb_iov_to_buf(const struct iovec *iov, const unsigned int= iov_cnt, + size_t offset, void *buf, size_t bytes) +{ + size_t done; + unsigned int i; + for (i =3D 0, done =3D 0; (offset || done < bytes) && i < iov_cnt; i++= ) { + if (offset < iov[i].iov_len) { + size_t len =3D MIN(iov[i].iov_len - offset, bytes - done); + memcpy(buf + done, iov[i].iov_base + offset, len); + done +=3D len; + offset =3D 0; + } else { + offset -=3D iov[i].iov_len; + } + } + assert(offset =3D=3D 0); + return done; +} + +static size_t vrpmb_iov_from_buf(const struct iovec *iov, unsigned int iov= _cnt, + size_t offset, const void *buf, size_t by= tes) +{ + size_t done; + unsigned int i; + for (i =3D 0, done =3D 0; (offset || done < bytes) && i < iov_cnt; i++= ) { + if (offset < iov[i].iov_len) { + size_t len =3D MIN(iov[i].iov_len - offset, bytes - done); + memcpy(iov[i].iov_base + offset, buf + done, len); + done +=3D len; + offset =3D 0; + } else { + offset -=3D iov[i].iov_len; + } + } + assert(offset =3D=3D 0); + return done; +} =20 static void vrpmb_panic(VuDev *dev, const char *msg) { @@ -142,19 +223,211 @@ vrpmb_set_config(VuDev *dev, const uint8_t *data, return 0; } =20 +/* + * vrpmb_update_mac_in_frame: + * + * From the spec: + * The MAC is calculated using HMAC SHA-256. It takes + * as input a key and a message. The key used for the MAC calculation + * is always the 256-bit RPMB authentication key. The message used as + * input to the MAC calculation is the concatenation of the fields in + * the RPMB frames excluding stuff bytes and the MAC itself. + * + * The code to do this has been lifted from the optee supplicant code + * which itself uses a 3 clause BSD chunk of code. + */ + +static void vrpmb_update_mac_in_frame(VuRpmb *r, struct virtio_rpmb_frame = *frm) +{ + hmac_sha256_ctx ctx; + static const int dlen =3D (sizeof(struct virtio_rpmb_frame) - + offsetof(struct virtio_rpmb_frame, data)); + + hmac_sha256_init(&ctx, r->key, RPMB_KEY_MAC_SIZE); + hmac_sha256_update(&ctx, frm->data, dlen); + hmac_sha256_final(&ctx, &frm->key_mac[0], 32); +} + +/* + * Handlers for individual control messages + */ + +/* + * vrpmb_handle_program_key: + * + * Program the device with our key. The spec is a little hazzy on if + * we respond straight away or we wait for the user to send a + * VIRTIO_RPMB_REQ_RESULT_READ request. + */ +static void vrpmb_handle_program_key(VuDev *dev, struct virtio_rpmb_frame = *frame) +{ + VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); + + /* + * Run the checks from: + * 5.12.6.1.1 Device Requirements: Device Operation: Program Key + */ + r->last_reqresp =3D VIRTIO_RPMB_RESP_PROGRAM_KEY; + + /* Fail if already programmed */ + if (r->key) { + g_debug("key already programmed"); + r->last_result =3D VIRTIO_RPMB_RES_WRITE_FAILURE; + } else if (be16toh(frame->block_count) !=3D 1) { + g_debug("weird block counts (%d)", frame->block_count); + r->last_result =3D VIRTIO_RPMB_RES_GENERAL_FAILURE; + } else { + r->key =3D g_memdup(&frame->key_mac[0], RPMB_KEY_MAC_SIZE); + r->last_result =3D VIRTIO_RPMB_RES_OK; + } + + g_info("%s: req_resp =3D %x, result =3D %x", __func__, + r->last_reqresp, r->last_result); + return; +} + +/* + * Return the result of the last message. This is only valid if the + * previous message was VIRTIO_RPMB_REQ_PROGRAM_KEY or + * VIRTIO_RPMB_REQ_DATA_WRITE. + * + * The frame should be freed once sent. + */ +static struct virtio_rpmb_frame * vrpmb_handle_result_read(VuDev *dev) +{ + VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); + struct virtio_rpmb_frame *resp =3D g_new0(struct virtio_rpmb_frame, 1); + + if (r->last_reqresp =3D=3D VIRTIO_RPMB_RESP_PROGRAM_KEY || + r->last_reqresp =3D=3D VIRTIO_RPMB_REQ_DATA_WRITE) { + resp->result =3D htobe16(r->last_result); + resp->req_resp =3D htobe16(r->last_reqresp); + } else { + resp->result =3D htobe16(VIRTIO_RPMB_RES_GENERAL_FAILURE); + } + + /* calculate HMAC */ + if (!r->key) { + resp->result =3D htobe16(VIRTIO_RPMB_RES_GENERAL_FAILURE); + } else { + vrpmb_update_mac_in_frame(r, resp); + } + + g_info("%s: result =3D %x req_resp =3D %x", __func__, + be16toh(resp->result), + be16toh(resp->req_resp)); + return resp; +} + +static void fmt_bytes(GString *s, uint8_t *bytes, int len) +{ + int i; + for (i =3D 0; i < len; i++) { + if (i % 16 =3D=3D 0) { + g_string_append_c(s, '\n'); + } + g_string_append_printf(s, "%x ", bytes[i]); + } +} + +static void vrpmb_dump_frame(struct virtio_rpmb_frame *frame) +{ + g_autoptr(GString) s =3D g_string_new("frame: "); + + g_string_append_printf(s, " %p\n", frame); + g_string_append_printf(s, "key_mac:"); + fmt_bytes(s, (uint8_t *) &frame->key_mac[0], 32); + g_string_append_printf(s, "\ndata:"); + fmt_bytes(s, (uint8_t *) &frame->data, 256); + g_string_append_printf(s, "\nnonce:"); + fmt_bytes(s, (uint8_t *) &frame->nonce, 16); + g_string_append_printf(s, "\nwrite_counter: %d\n", + be32toh(frame->write_counter)); + g_string_append_printf(s, "address: %#04x\n", be16toh(frame->address)); + g_string_append_printf(s, "block_count: %d\n", be16toh(frame->block_co= unt)); + g_string_append_printf(s, "result: %d\n", be16toh(frame->result)); + g_string_append_printf(s, "req_resp: %d\n", be16toh(frame->req_resp)); + + g_debug("%s: %s\n", __func__, s->str); +} + static void vrpmb_handle_ctrl(VuDev *dev, int qidx) { VuVirtq *vq =3D vu_get_queue(dev, qidx); - struct virtio_rpmb_ctrl_command *cmd =3D NULL; + struct virtio_rpmb_frame *frames =3D NULL; =20 for (;;) { - cmd =3D vu_queue_pop(dev, vq, sizeof(struct virtio_rpmb_ctrl_comma= nd)); - if (!cmd) { + VuVirtqElement *elem; + size_t len, frame_sz =3D sizeof(struct virtio_rpmb_frame); + int n; + + elem =3D vu_queue_pop(dev, vq, sizeof(VuVirtqElement)); + if (!elem) { break; } + g_debug("%s: got queue (in %d, out %d)", __func__, + elem->in_num, elem->out_num); =20 - g_debug("un-handled cmd: %p", cmd); + len =3D vrpmb_iov_size(elem->out_sg, elem->out_num); + frames =3D g_realloc(frames, len); + vrpmb_iov_to_buf(elem->out_sg, elem->out_num, 0, frames, len); + + if (len % frame_sz !=3D 0) { + g_warning("%s: incomplete frames %zu/%zu !=3D 0\n", + __func__, len, frame_sz); + } + + for (n =3D 0; n < len / frame_sz; n++) { + struct virtio_rpmb_frame *f =3D &frames[n]; + struct virtio_rpmb_frame *resp =3D NULL; + uint16_t req_resp =3D be16toh(f->req_resp); + bool responded =3D false; + + if (debug) { + g_info("req_resp=3D%x", req_resp); + vrpmb_dump_frame(f); + } + + switch (req_resp) { + case VIRTIO_RPMB_REQ_PROGRAM_KEY: + vrpmb_handle_program_key(dev, f); + break; + case VIRTIO_RPMB_REQ_RESULT_READ: + if (!responded) { + resp =3D vrpmb_handle_result_read(dev); + } else { + g_warning("%s: already sent a response in this set of = frames", + __func__); + } + break; + default: + g_debug("un-handled request: %x", f->req_resp); + break; + } + + /* + * Do we have a frame to send back? + */ + if (resp) { + g_debug("sending response frame: %p", resp); + if (debug) { + vrpmb_dump_frame(resp); + } + len =3D vrpmb_iov_from_buf(elem->in_sg, + elem->in_num, 0, resp, sizeof(*re= sp)); + if (len !=3D sizeof(*resp)) { + g_critical("%s: response size incorrect %zu vs %zu", + __func__, len, sizeof(*resp)); + } else { + vu_queue_push(dev, vq, elem, len); + vu_queue_notify(dev, vq); + responded =3D true; + } + + g_free(resp); + } + } } } =20 --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601039485; cv=none; d=zohomail.com; s=zohoarc; b=dgna0na3NtTVwm+SwrNrP+PPTPgkf7ZgeZTSHUKY3GtkvbSxUmBjLQBOIU+0Ixa+4YCjc4/B25VZRzAZrpeAlxdA+ECMaM9WyVY0sdeqENSbhPH/bqFVVNwlWYIJ7ovKJL/s6BFQhFXbGOeG3sZuFhd3uLyHQcy5gTbhbY+QNt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601039485; 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=kjcelvvovVPpABaKJSYVdSxl5UaJWqhfw0gOadK/FqU=; b=SWSndRcLSxdgnDMGbq3f969ptsY5adxieSd2LxU98Dn1M2HMKiSBBGs4WHYE11k4Yaefgv1nNgrGHibFi8VVzZOiUdUYpHo69bmqMZhZMR9EW0fBseP4jzwT62Vc9cW2+IcsQJSNF0AhmFtoWOHvqNZW5psXOjsWxd+El3w1LTA= 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 1601039485797464.11390531783206; Fri, 25 Sep 2020 06:11:25 -0700 (PDT) Received: from localhost ([::1]:35258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnVU-0006qR-Gd for importer@patchew.org; Fri, 25 Sep 2020 09:11:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnJl-0002dg-IP for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:17 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnJi-0002Hd-Gk for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:17 -0400 Received: by mail-wr1-x441.google.com with SMTP id z1so3525646wrt.3 for ; Fri, 25 Sep 2020 05:59:14 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id l17sm2777107wme.11.2020.09.25.05.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:59:10 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 8BC0F1FF9D; 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=kjcelvvovVPpABaKJSYVdSxl5UaJWqhfw0gOadK/FqU=; b=rFOBI8Z/RXPzGJ54j6yDyARsXqgXrWBJScBJqf9ABJFKS4dAg2QKZTqsQJ2e6b6XVL klf2Dfm1xFQGAAPaQFKYdDHmI2g6rKakJuzlIdVR/Jo1ycHmcurFG+nShetNucqKayf+ 9nL6g6xloQjox9U6xWTlVhh2alG5a9qNEZUvqJ0Y86VwBrnNMWmtjs3PNuS3wFCC2+Vk q95Kdzk0/5A4F5xPYWVDQi6Xhlfi/qh6/EySkqZZ5h8Y7DDhs1oh3dRKMyv802zPDGLI LCGCTS60G8uBxOxCb/PYZpBVt1hHMJuOv1MLBxM1POI3XUfYvu3HfIf76ymgi9Wqzedm y1kQ== 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=kjcelvvovVPpABaKJSYVdSxl5UaJWqhfw0gOadK/FqU=; b=V7FrC869FYX9voVrS6ylrxMzEJMAVc37kF901+DjihSulV9/pNc7A9ZdJ63ZMYfh1d bLooo4TyNFkMTgTi6gkhQrvSU8/p+OEKJp7aksbhHq0jVbfvCyfq/0vfIo8t1ox461DP DW1gKTCp6Hhtwbkh6agfBN9HFj+DUeu7DDx/tvKvxYu07TYD6hHlvBF99u0DVuKePc6Y tUFRZn91qGrNQhwJ6VvQNA6OD/vufAK2mWW15heuhjUohLDhptV2+AzP/Ms2O6JMmjo3 nojlEaE6nhfupdGdvsdrzg6LTNFwf0IjmhNmjsJVmGTYPqIhSjG4RhPGRMtIZROA4OG4 +1Ww== X-Gm-Message-State: AOAM530bKe+oWM43+ZqQbyL5r/LcsDNCvZF0uE0xPH0g0tuSK2dZ0BWA S4Ixv8C6Hlm9lruWkqHb4JPFgg== X-Google-Smtp-Source: ABdhPJz/pSEUzxyT825aVOOpaDQxurDcxtpN6iSAvnZnK6Jj718Enur34F0X+qcoNK0bh0dijaHmJg== X-Received: by 2002:adf:dfc9:: with SMTP id q9mr4334999wrn.400.1601038753214; Fri, 25 Sep 2020 05:59:13 -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 14/19] tools/vhost-user-rpmb: implement VIRTIO_RPMB_REQ_GET_WRITE_COUNTER Date: Fri, 25 Sep 2020 13:51:42 +0100 Message-Id: <20200925125147.26943-15-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) This is the first function with an implied response that doesn't need a VIRTIO_RPMB_REQ_RESULT_READ. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 9c98f6916f6f..88747c50fa44 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -121,8 +121,10 @@ typedef struct VuRpmb { int flash_fd; void *flash_map; uint8_t *key; + uint8_t last_nonce[16]; uint16_t last_result; uint16_t last_reqresp; + uint32_t write_count; } VuRpmb; =20 /* refer to util/iov.c */ @@ -286,6 +288,42 @@ static void vrpmb_handle_program_key(VuDev *dev, struc= t virtio_rpmb_frame *frame return; } =20 +/* + * vrpmb_handle_get_write_counter: + * + * We respond straight away with re-using the frame as sent. + */ +static struct virtio_rpmb_frame * +vrpmb_handle_get_write_counter(VuDev *dev, struct virtio_rpmb_frame *frame) +{ + VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); + struct virtio_rpmb_frame *resp =3D g_new0(struct virtio_rpmb_frame, 1); + + /* + * Run the checks from: + * 5.12.6.1.2 Device Requirements: Device Operation: Get Write Counter + */ + + resp->req_resp =3D htobe16(VIRTIO_RPMB_RESP_GET_COUNTER); + if (!r->key) { + g_debug("no key programmed"); + resp->result =3D htobe16(VIRTIO_RPMB_RES_NO_AUTH_KEY); + return resp; + } else if (be16toh(frame->block_count) > 1) { /* allow 0 (NONCONF) */ + g_debug("invalid block count (%d)", be16toh(frame->block_count)); + resp->result =3D htobe16(VIRTIO_RPMB_RES_GENERAL_FAILURE); + } else { + resp->write_counter =3D htobe32(r->write_count); + } + /* copy nonce */ + memcpy(&resp->nonce, &frame->nonce, sizeof(frame->nonce)); + + /* calculate MAC */ + vrpmb_update_mac_in_frame(r, resp); + + return resp; +} + /* * Return the result of the last message. This is only valid if the * previous message was VIRTIO_RPMB_REQ_PROGRAM_KEY or @@ -298,6 +336,9 @@ static struct virtio_rpmb_frame * vrpmb_handle_result_r= ead(VuDev *dev) VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); struct virtio_rpmb_frame *resp =3D g_new0(struct virtio_rpmb_frame, 1); =20 + g_info("%s: for request:%x result:%x", __func__, + r->last_reqresp, r->last_result); + if (r->last_reqresp =3D=3D VIRTIO_RPMB_RESP_PROGRAM_KEY || r->last_reqresp =3D=3D VIRTIO_RPMB_REQ_DATA_WRITE) { resp->result =3D htobe16(r->last_result); @@ -393,6 +434,9 @@ vrpmb_handle_ctrl(VuDev *dev, int qidx) case VIRTIO_RPMB_REQ_PROGRAM_KEY: vrpmb_handle_program_key(dev, f); break; + case VIRTIO_RPMB_REQ_GET_WRITE_COUNTER: + resp =3D vrpmb_handle_get_write_counter(dev, f); + break; case VIRTIO_RPMB_REQ_RESULT_READ: if (!responded) { resp =3D vrpmb_handle_result_read(dev); --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601039372; cv=none; d=zohomail.com; s=zohoarc; b=KhkGxfDiJBYH7ot3fsBm4IU0rccGnuAFc6XLpAl4jQh6z7O5hDW42qsl478uk8VmJr0CrRPgu2VbhCtSqCTYxSn0N3IXv1WUywhU0nofdDcn1uRRGWua6bqPYYu3imhcBv8vY2Tq2TKLaMQ3uzQG3WV0L7lGFZe3eGQrH/BUNgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601039372; 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=L9eT1oZ9PgrU1jdXi7fYi4acA1czIwdtwVY/kAyMWRU=; b=i6fFC9cNTtXKXpiVbDC0r3SR9sghOfir+DZEGaZUaDo8ACi6S4qkOu2hr28Yx2RJt2JtyBGHz9dKFGK/ryo9GQaMPijOrRP6fT78Ef2GQ0GOok2HNLpShYO5Xq5A+1rniFoUctWCWgIWsSM4m063NTulr3LYSmsIlxIAf6gChQY= 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 1601039372783485.6823937560358; Fri, 25 Sep 2020 06:09:32 -0700 (PDT) Received: from localhost ([::1]:57928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnTf-0004OH-BH for importer@patchew.org; Fri, 25 Sep 2020 09:09:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnJc-0002QT-Qz for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:08 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:34457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnJa-0002GH-Kk for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:08 -0400 Received: by mail-wr1-x443.google.com with SMTP id t10so3550056wrv.1 for ; Fri, 25 Sep 2020 05:59:06 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u63sm2867369wmb.13.2020.09.25.05.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:59:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A112E1FF9E; 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=L9eT1oZ9PgrU1jdXi7fYi4acA1czIwdtwVY/kAyMWRU=; b=zT3p1w6zUFNJ20/+EwFBQqMR+Y5rKNFb9ZY04ww0i/XqWnq5j5v4z8NxLDJBr+Us/1 wTdtmpy4LKMBgniZ9C6xNXpgGff8U/mvjX+cd3niKGQnc1c6FcFUXXpDawolWTT4E5b4 0FmTYLVplO2F+SbcpE8R4a1vX6BW0O4nWnr6dDex7VK7Qqx4vDo1f7QPh60180QERAyk NNIgjw04m/V0krJh01tzmrUP5XXxMiv+4PDk0RXDSN06k6VMbJ1jE8RI3M13G4FSwOXr 9waI5ISaS3T8Rcpfv7dQxKijf2l38ytY5793syneVyry9t1rp88sisn/yqDIpoayZ5DL /WHg== 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=L9eT1oZ9PgrU1jdXi7fYi4acA1czIwdtwVY/kAyMWRU=; b=IR/Clz/IW6FXzyXy9+ASefnRb6OxjWNiCJJIlcvJUB737rEKw778z3lhDHxxnNxpZj u0AyGhOiPyH6gESSTnM6k1W8No+AGBP6q0ZUH3EwkJM8BIGfXTpEeZyHZWmqDTSgo1CC szptp8dovbWBtJ1Ue7c8I7NdjAC4jvqCoQGxj03Y12eM0zDXCnV4ko+yIi9BRC79f0pm ndK6Czrx/smt+cnPI3AAhlF5UXfLQ7t2G4cmzJz10fsO94PsXFQk5BE/f1UOQtC5PXpm Ew4nk06JLlULZYeYse6CapsiqURaBvGr5KWPzn+FVonVYqFDWzyt/UCSlqAGizZNR5Yu kQNA== X-Gm-Message-State: AOAM533eZsO755RF8NwdGwToV4YTSmPL0o9aeSVOD/Qz0h1FAXVNxNqq nyjdJ3jB3uj97xUPYcoz13xR7w== X-Google-Smtp-Source: ABdhPJy5z2JTSE7xjlqn9lmm3x6ZThm35XF11X2xktR9qINldTWdDf5oKrIdHbtjdTA4P0VidpRpFw== X-Received: by 2002:a5d:574c:: with SMTP id q12mr4373496wrw.253.1601038744992; Fri, 25 Sep 2020 05:59:04 -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 15/19] tools/vhost-user-rpmb: implement VIRTIO_RPMB_REQ_DATA_WRITE Date: Fri, 25 Sep 2020 13:51:43 +0100 Message-Id: <20200925125147.26943-16-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::443; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x443.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) With this command we are finally updating data to the backing store and cycling the write_count and each successful write. We also include the write count in all response frames as the spec is a little unclear but the example test code expected it. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 111 +++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 6 deletions(-) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 88747c50fa44..a17c3b4bcc4e 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -62,6 +62,7 @@ enum { #define KiB (1UL << 10) #define MAX_RPMB_SIZE (KiB * 128 * 256) #define RPMB_KEY_MAC_SIZE 32 +#define RPMB_BLOCK_SIZE 256 =20 /* RPMB Request Types */ #define VIRTIO_RPMB_REQ_PROGRAM_KEY 0x0001 @@ -100,7 +101,7 @@ struct virtio_rpmb_config { struct virtio_rpmb_frame { uint8_t stuff[196]; uint8_t key_mac[RPMB_KEY_MAC_SIZE]; - uint8_t data[256]; + uint8_t data[RPMB_BLOCK_SIZE]; uint8_t nonce[16]; /* remaining fields are big-endian */ uint32_t write_counter; @@ -124,6 +125,7 @@ typedef struct VuRpmb { uint8_t last_nonce[16]; uint16_t last_result; uint16_t last_reqresp; + uint16_t last_address; uint32_t write_count; } VuRpmb; =20 @@ -239,17 +241,30 @@ vrpmb_set_config(VuDev *dev, const uint8_t *data, * which itself uses a 3 clause BSD chunk of code. */ =20 +static const int rpmb_frame_dlen =3D (sizeof(struct virtio_rpmb_frame) - + offsetof(struct virtio_rpmb_frame, dat= a)); + static void vrpmb_update_mac_in_frame(VuRpmb *r, struct virtio_rpmb_frame = *frm) { hmac_sha256_ctx ctx; - static const int dlen =3D (sizeof(struct virtio_rpmb_frame) - - offsetof(struct virtio_rpmb_frame, data)); =20 hmac_sha256_init(&ctx, r->key, RPMB_KEY_MAC_SIZE); - hmac_sha256_update(&ctx, frm->data, dlen); + hmac_sha256_update(&ctx, frm->data, rpmb_frame_dlen); hmac_sha256_final(&ctx, &frm->key_mac[0], 32); } =20 +static bool vrpmb_verify_mac_in_frame(VuRpmb *r, struct virtio_rpmb_frame = *frm) +{ + hmac_sha256_ctx ctx; + uint8_t calculated_mac[RPMB_KEY_MAC_SIZE]; + + hmac_sha256_init(&ctx, r->key, RPMB_KEY_MAC_SIZE); + hmac_sha256_update(&ctx, frm->data, rpmb_frame_dlen); + hmac_sha256_final(&ctx, calculated_mac, RPMB_KEY_MAC_SIZE); + + return memcmp(calculated_mac, frm->key_mac, RPMB_KEY_MAC_SIZE) =3D=3D = 0; +} + /* * Handlers for individual control messages */ @@ -324,6 +339,82 @@ vrpmb_handle_get_write_counter(VuDev *dev, struct virt= io_rpmb_frame *frame) return resp; } =20 +/* + * vrpmb_handle_write: + * + * We will report the success/fail on receipt of + * VIRTIO_RPMB_REQ_RESULT_READ. Returns the number of extra frames + * processed in the request. + */ +static int vrpmb_handle_write(VuDev *dev, struct virtio_rpmb_frame *frame) +{ + VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); + int extra_frames =3D 0; + uint16_t block_count =3D be16toh(frame->block_count); + uint32_t write_counter =3D be32toh(frame->write_counter); + size_t offset; + + r->last_reqresp =3D VIRTIO_RPMB_RESP_DATA_WRITE; + r->last_address =3D be16toh(frame->address); + offset =3D r->last_address * RPMB_BLOCK_SIZE; + + /* + * Run the checks from: + * 5.12.6.1.3 Device Requirements: Device Operation: Data Write + */ + if (!r->key) { + g_warning("no key programmed"); + r->last_result =3D VIRTIO_RPMB_RES_NO_AUTH_KEY; + } else if (block_count =3D=3D 0 || + block_count > r->virtio_config.max_wr_cnt) { + r->last_result =3D VIRTIO_RPMB_RES_GENERAL_FAILURE; + } else if (false /* what does an expired write counter mean? */) { + r->last_result =3D VIRTIO_RPMB_RES_WRITE_COUNTER_EXPIRED; + } else if (offset > (r->virtio_config.capacity * (128 * KiB))) { + r->last_result =3D VIRTIO_RPMB_RES_ADDR_FAILURE; + } else if (!vrpmb_verify_mac_in_frame(r, frame)) { + r->last_result =3D VIRTIO_RPMB_RES_AUTH_FAILURE; + } else if (write_counter !=3D r->write_count) { + r->last_result =3D VIRTIO_RPMB_RES_COUNT_FAILURE; + } else { + int i; + /* At this point we have a valid authenticated write request + * so the counter can incremented and we can attempt to + * update the backing device. + */ + r->write_count++; + for (i =3D 0; i < block_count; i++) { + void *blk =3D r->flash_map + offset; + g_debug("%s: writing block %d", __func__, i); + if (mprotect(blk, RPMB_BLOCK_SIZE, PROT_WRITE) !=3D 0) { + r->last_result =3D VIRTIO_RPMB_RES_WRITE_FAILURE; + break; + } + memcpy(blk, frame[i].data, RPMB_BLOCK_SIZE); + if (msync(blk, RPMB_BLOCK_SIZE, MS_SYNC) !=3D 0) { + g_warning("%s: failed to sync update", __func__); + r->last_result =3D VIRTIO_RPMB_RES_WRITE_FAILURE; + break; + } + if (mprotect(blk, RPMB_BLOCK_SIZE, PROT_READ) !=3D 0) { + g_warning("%s: failed to re-apply read protection", __func= __); + r->last_result =3D VIRTIO_RPMB_RES_GENERAL_FAILURE; + break; + } + offset +=3D RPMB_BLOCK_SIZE; + } + r->last_result =3D VIRTIO_RPMB_RES_OK; + extra_frames =3D i - 1; + } + + g_info("%s: %s (%x, %d extra frames processed), write_count=3D%d", __f= unc__, + r->last_result =3D=3D VIRTIO_RPMB_RES_OK ? "successful":"failed= ", + r->last_result, extra_frames, r->write_count); + + return extra_frames; +} + + /* * Return the result of the last message. This is only valid if the * previous message was VIRTIO_RPMB_REQ_PROGRAM_KEY or @@ -339,10 +430,14 @@ static struct virtio_rpmb_frame * vrpmb_handle_result= _read(VuDev *dev) g_info("%s: for request:%x result:%x", __func__, r->last_reqresp, r->last_result); =20 - if (r->last_reqresp =3D=3D VIRTIO_RPMB_RESP_PROGRAM_KEY || - r->last_reqresp =3D=3D VIRTIO_RPMB_REQ_DATA_WRITE) { + if (r->last_reqresp =3D=3D VIRTIO_RPMB_RESP_PROGRAM_KEY) { resp->result =3D htobe16(r->last_result); resp->req_resp =3D htobe16(r->last_reqresp); + } else if (r->last_reqresp =3D=3D VIRTIO_RPMB_RESP_DATA_WRITE) { + resp->result =3D htobe16(r->last_result); + resp->req_resp =3D htobe16(r->last_reqresp); + resp->write_counter =3D htobe32(r->write_count); + resp->address =3D htobe16(r->last_address); } else { resp->result =3D htobe16(VIRTIO_RPMB_RES_GENERAL_FAILURE); } @@ -445,6 +540,10 @@ vrpmb_handle_ctrl(VuDev *dev, int qidx) __func__); } break; + case VIRTIO_RPMB_REQ_DATA_WRITE: + /* we can have multiple blocks handled */ + n +=3D vrpmb_handle_write(dev, f); + break; default: g_debug("un-handled request: %x", f->req_resp); break; --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601039489; cv=none; d=zohomail.com; s=zohoarc; b=KmYfoNpx7E+8it3UZiWXlgimDBXO1jBXfSl7Z8ZPFSD/u+v9/KaZpG7cCWk/2b0c0tvUg5Yo3o90bBYGueetD7n7JZU5viOx7GoIPsQZ/lnY+SI1q3m0AFdkLSJs5MyFyo5VkZGnUqzHDoW0rP9+hVFLEKt9cSLF3nHpu7Z5ras= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601039489; 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=uzbbYkb4NnbTBJGCofcpI1INW2euUpldKIpyeVgpePE=; b=S5pCd/pmEDeY4cEOORBFV+eY/M4Ua0vk6Tyv3ueGZxSLaSWOErWdXvmC8L6LzUsbH79nt5sVSSrhlSt8EEGIXwgw3i9Ew2nOU1pNwgBNs0Do0NUqREJlC0ePiLG0B2gcqYVBIIwZwmQayVyEhwf84dpdLD0gGnQXSxEJx2wLDhw= 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 1601039489349593.6636654656761; Fri, 25 Sep 2020 06:11:29 -0700 (PDT) Received: from localhost ([::1]:35672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnVX-00070j-RL for importer@patchew.org; Fri, 25 Sep 2020 09:11:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnJe-0002V5-H3 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:10 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:40023) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnJc-0002GW-JB for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:10 -0400 Received: by mail-wr1-x442.google.com with SMTP id j2so3500833wrx.7 for ; Fri, 25 Sep 2020 05:59:08 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a17sm3054427wra.24.2020.09.25.05.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:59:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B5F5C1FF9F; 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=uzbbYkb4NnbTBJGCofcpI1INW2euUpldKIpyeVgpePE=; b=G/4+NjmMBCwOaEnAD8G4WHhVWosqSJutwj2jU41+Wz3f+z5Pu+x3w+Apvq4vw/gI6v OWEZlnT5uP58hV4MyLlM6VfpFHdnUJ4oqdaUQf4zXdNX3SOuQgljdobicUopdh9+6Ttb tXUTPX9pd8fHN81fYhE73C+f0Vr4nbSfPJs/eTSm7mBApwHMwISTgoEUPS1o/1aTGy59 Ly1MU/lRmWaDwMuBlaDKximatvYG0mrhUzV1I42Ya1KBavcxdPG4gy+D1vTEfCiEcnNY 0b0zurgjWbBhlZV/04f0ObAWGAtX/EUic+h5M9zvFuDlqSnXZHFaMy2ek4+dRMByrReH XEZA== 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=uzbbYkb4NnbTBJGCofcpI1INW2euUpldKIpyeVgpePE=; b=JdkuRMINdU1TX4ZOidrCAn93NmhK6xGD6kINi6LCGvTdv6VCw/pTUmJ6kWk8b/M/at /V6nr8IkzMU/rVZFiZTVfbdxytib9r8sJ4xrPFB065GiiGv9jdjwTi52KVaxS0r3JfM8 cGnuiBX8QE/RgjblD48Zl78NUy0TH1h3vS5rNHHeW+S0kc8aIem6dp85b0aYVIO5J93+ RxOLNEquceq5HnaPVByZCCCXqPB0NdFQiSZyrzpgV0PaU17ydWAItBFXeV/iaSrQPxaN ZMQ88hFl/7SoQ/YkUX4f/OpV+WC6zwZBrqHVjebPGmPLW30jTSa0L02JdBtEgK7eT2yM Uz/Q== X-Gm-Message-State: AOAM533IvYLjrNGQl57h1sYHsNSDRUQDYSy7WUn9DeBaclDQc/ZPT5UC 3DHkYk8Qq8gtQlcJOOczKPJ4sg== X-Google-Smtp-Source: ABdhPJy8Ipyz4jx7i9Y+XtUqRtfhW1VyFR6m8SCZSQPxBY5fr63M/xHX3v8k/G7hF1I7i6WrR75kfg== X-Received: by 2002:a5d:4645:: with SMTP id j5mr4392648wrs.230.1601038747151; Fri, 25 Sep 2020 05:59: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 16/19] tools/vhost-user-rpmb: implement VIRTIO_RPMB_REQ_DATA_READ Date: Fri, 25 Sep 2020 13:51:44 +0100 Message-Id: <20200925125147.26943-17-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::442; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x442.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) The read command is a lot simpler to implement. However the spec does specify you can only read a single block at a time so we limit it to that. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index a17c3b4bcc4e..49d4e00b24a9 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -414,6 +414,55 @@ static int vrpmb_handle_write(VuDev *dev, struct virti= o_rpmb_frame *frame) return extra_frames; } =20 +/* + * vrpmb_handle_read: + * + * Unlike the write operation we return a frame with the result of the + * read here. While the config specifies a maximum read count the spec + * is limited to a single read at a time. + */ +static struct virtio_rpmb_frame * +vrpmb_handle_read(VuDev *dev, struct virtio_rpmb_frame *frame) +{ + VuRpmb *r =3D container_of(dev, VuRpmb, dev.parent); + size_t offset =3D be16toh(frame->address) * RPMB_BLOCK_SIZE; + uint16_t block_count =3D be16toh(frame->block_count); + struct virtio_rpmb_frame *resp =3D g_new0(struct virtio_rpmb_frame, 1); + + resp->req_resp =3D htobe16(VIRTIO_RPMB_RESP_DATA_READ); + resp->address =3D frame->address; + resp->block_count =3D htobe16(1); + + /* + * Run the checks from: + * 5.12.6.1.4 Device Requirements: Device Operation: Data Read + */ + if (!r->key) { + g_warning("no key programmed"); + resp->result =3D htobe16(VIRTIO_RPMB_RES_NO_AUTH_KEY); + } else if (block_count !=3D 1) { + /* + * Despite the config the spec only allows for reading one + * block at a time: "If block count has not been set to 1 then + * VIRTIO_RPMB_RES_GENERAL_FAILURE SHOULD be responded as + * result." + */ + resp->result =3D htobe16(VIRTIO_RPMB_RES_GENERAL_FAILURE); + } else if (offset > (r->virtio_config.capacity * (128 * KiB))) { + resp->result =3D htobe16(VIRTIO_RPMB_RES_ADDR_FAILURE); + } else { + void *blk =3D r->flash_map + offset; + g_debug("%s: reading block from %p (%zu)", __func__, blk, offset); + memcpy(resp->data, blk, RPMB_BLOCK_SIZE); + resp->result =3D htobe16(VIRTIO_RPMB_RES_OK); + } + + /* Final housekeeping, copy nonce and calculate MAC */ + memcpy(&resp->nonce, &frame->nonce, sizeof(frame->nonce)); + vrpmb_update_mac_in_frame(r, resp); + + return resp; +} =20 /* * Return the result of the last message. This is only valid if the @@ -544,6 +593,9 @@ vrpmb_handle_ctrl(VuDev *dev, int qidx) /* we can have multiple blocks handled */ n +=3D vrpmb_handle_write(dev, f); break; + case VIRTIO_RPMB_REQ_DATA_READ: + resp =3D vrpmb_handle_read(dev, f); + break; default: g_debug("un-handled request: %x", f->req_resp); break; --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601038979; cv=none; d=zohomail.com; s=zohoarc; b=jKUP8cvyheptf9ScZb5N2z8WX6yvSJzTS0oxBQX/2smlIEVUEg53lLAOIM0M6m7AtbNFEwEvxoHsFubdY+89TnZwkGVxwWxy98RYiObKJw+MSpMUaavIjj/dtUnBuxmGN+CVrKoBpi3vIr9mKTaNULc3BbbNV/o3Jub8iRGkjE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601038979; 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=9fkNiykv8ADFgLC/XdCeeBy0xSrSjYwQRRXXIjcsZfQ=; b=UadntETN/4zDSqMYEvWRxLHHYQYgX1WZRhYVQg8/0KHsl6a2jPJuo5Rky08gCH2r5r0+0u13V+rzCOp3L+EFGGP9B9PeNaDRGmC+mk4BtUgdZZcdT/9hTQxkNcaIRRH5yJGW0r0U9ESFHX3sghb/vAI28GAR/glAGhwTB1uyoIA= 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 1601038979604587.7915044808888; Fri, 25 Sep 2020 06:02:59 -0700 (PDT) Received: from localhost ([::1]:38736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnNK-0004HI-59 for importer@patchew.org; Fri, 25 Sep 2020 09:02:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnJb-0002Od-UY for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:07 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:32882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnJZ-0002G2-Rd for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:07 -0400 Received: by mail-wr1-x441.google.com with SMTP id m6so3553835wrn.0 for ; Fri, 25 Sep 2020 05:59:05 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w7sm2681834wmc.43.2020.09.25.05.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:59:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id CBB9F1FFA5; 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=9fkNiykv8ADFgLC/XdCeeBy0xSrSjYwQRRXXIjcsZfQ=; b=ng2mbfBaraUgOB2YcxAblz8zL/B2JiLaRmUITJQx7pI/RpR/qZr0cy2sSwPxSWDRCT GOaiiUyVeZnnyMd1JAeliXANvRli3jJpypwA3K+piwLhuP58yghIcf2FHiK3i/I6w8Y2 8squPohCNbuCKFU5zycOQ2ZA3fuUfBDWeB/2H+4NN/Wa74uEGyo5zIiRZuqBPj2f236o ysTS4djRAw3rwKqug6u+wsiLi66HBgznwi/DWJUcKL3s9UEKzPg0EaXjnDVUL56+Kn19 jG/A0xENSMpLe761AysdmZZjWvB7DK8NqKj8nvYZ/pOdT7FBFcx6MaCzt9mDFEu9quNV +F/A== 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=9fkNiykv8ADFgLC/XdCeeBy0xSrSjYwQRRXXIjcsZfQ=; b=B5zcq7s+cgMK/Eo9Rxf8awPfJlAVQGUUi3m2bsOGLnfOvtKV9KwclFEiCeFjmPUOcK 3pLZ3+PrbxqF0WfFupDNnz+8OJVxEp+YjHjSjxsLuj7dW33TiXmQnLjdbyrUMnLeOhKi bpCbKLetifu/2yLwlttGdoYMHHshsLxDvSdtkzup3QeCMizwKzh4nlMY8CCUheRaIIDt VO0LI4S7499iJymbUIfqijf+IE8OeohFSS6+eOiHMlNSQ9zbyOynRTqW3IkI5NF8Wdky pDx/74a0u9wGmYPqGc304QNBzUt710FxawKQnOY8ymVSnxeak1i3rvcdyd+Vd7BfWzmb YS2Q== X-Gm-Message-State: AOAM531Ti6Q8jlWRMbuNAjchCQUliITJriZopL+qtziy3BtlI3MKYmEB q6iFC5Ku4S6yBlSu5L59NVQgGQ== X-Google-Smtp-Source: ABdhPJwZXb/aMNaYKd7Fb9nlyToAZPmVmFIUciP/z/7p3m/cMVRnn2njwc65CUypQ59VcJIyBLwOWg== X-Received: by 2002:adf:ec47:: with SMTP id w7mr4681024wrn.175.1601038743834; Fri, 25 Sep 2020 05:59:03 -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 17/19] tools/vhost-user-rpmb: add key persistence Date: Fri, 25 Sep 2020 13:51:45 +0100 Message-Id: <20200925125147.26943-18-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) Add support for persisting the key in --key-path. By default it will accept the program-key command and store the key in the key file. If you pass --key-set then the key is deemed to be programmed and can't be re-programmed. Obviously you will need some other mechanism to let the guest know what the key is so it can do other operations. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 49d4e00b24a9..34607ad19429 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -38,15 +38,19 @@ =20 static gchar *socket_path; static char *flash_path; +static char *key_path; static gint socket_fd =3D -1; static gboolean print_cap; static gboolean verbose; static gboolean debug; +static gboolean key_set; =20 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" }, + { "key-path", 0, 0, G_OPTION_ARG_FILENAME, &key_path, "Location of per= sistent keyfile", "KEY"}, + { "key-set", 0, 0, G_OPTION_ARG_NONE, &key_set, "Is the key already pr= ogrammed", NULL}, { "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}, @@ -296,8 +300,18 @@ static void vrpmb_handle_program_key(VuDev *dev, struc= t virtio_rpmb_frame *frame } else { r->key =3D g_memdup(&frame->key_mac[0], RPMB_KEY_MAC_SIZE); r->last_result =3D VIRTIO_RPMB_RES_OK; + if (key_path) { + GError *err =3D NULL; + if (!g_file_set_contents(key_path, (char *) r->key, + RPMB_KEY_MAC_SIZE, &err)) { + g_warning("%s: unable to persist key data to %s: %s", + __func__, key_path, err->message); + g_error_free(err); + } + } } =20 + g_info("%s: req_resp =3D %x, result =3D %x", __func__, r->last_reqresp, r->last_result); return; @@ -709,6 +723,25 @@ static bool vrpmb_load_flash_image(VuRpmb *r, char *im= g_path) return true; } =20 +static void vrpmb_set_key(VuRpmb *r, char *key_path) +{ + GError *err =3D NULL; + gsize length; + + if (!g_file_get_contents(key_path, (char **) &r->key, &length, &err)) { + g_print("Unable to read %s: %s", key_path, err->message); + exit(1); + } + if (length < RPMB_KEY_MAC_SIZE) { + g_print("key file to small %ld < %d", length, RPMB_KEY_MAC_SIZE); + exit(1); + } else if (length > RPMB_KEY_MAC_SIZE) { + /* being too big isn't fatal, we just ignore the excess */ + g_warning("%ld bytes of %s ignore (file too big)", + length - RPMB_KEY_MAC_SIZE, key_path); + } +} + static void vrpmb_destroy(VuRpmb *r) { vug_deinit(&r->dev); @@ -760,6 +793,10 @@ int main(int argc, char *argv[]) vrpmb_load_flash_image(&rpmb, flash_path); } =20 + if (key_path && key_set) { + vrpmb_set_key(&rpmb, key_path); + } + if (!socket_path && socket_fd < 0) { g_printerr("Please specify either --fd or --socket-path\n"); exit(EXIT_FAILURE); --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601039638; cv=none; d=zohomail.com; s=zohoarc; b=UMRcEnFLp1YOfDPIwFXo06/F24GvalRW6F+tunKZPGmeyaXHf84YqnSYyRl/KMLeT6BhqAxMzm6uHU2Bf72TSh5s4hCLmLA4WGWKYNZH7B6TvXFzyOEvI5kSmPQTrzIKqOGpNgogAHBjaYPM3HVBkFOH4+4dVYKWnP2XIkoKNTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601039638; 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=sln1IsFPWRFtNzDapJfqz9D0UXVcbAOIwCVnS/WVrtY=; b=WEP6gEo6Q9Z5SLyKkQ7vEbQ1MGXoB5TBaF3vtlOvJvgNFvaMl8XJ8lkJq+FD7dxCw0d+TunrkJrJwGk0FTklAsSOC4pPH7WmylRnJk9S0ldvEyJeTSQ3t+W4lqdwvscZieQGszJmQRVeSXOrYURKabXd0FvYWyTnqRsU9ySgv3A= 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 1601039638083581.0658183940549; Fri, 25 Sep 2020 06:13:58 -0700 (PDT) Received: from localhost ([::1]:43862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnXw-00023j-EW for importer@patchew.org; Fri, 25 Sep 2020 09:13:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnJf-0002WQ-LD for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:12 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnJd-0002Gh-G9 for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:11 -0400 Received: by mail-wm1-x344.google.com with SMTP id y15so3208965wmi.0 for ; Fri, 25 Sep 2020 05:59:09 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n2sm3112612wma.29.2020.09.25.05.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:59:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E2DCB1FFA6; 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=sln1IsFPWRFtNzDapJfqz9D0UXVcbAOIwCVnS/WVrtY=; b=ZBulUDn5etyg+1dgFomway7kca2EbjmeP6HXXUn2kPBv7e7AxynvYVSXdfxdyMdsoU xEK2ZtRZVQD+4fy7Et8CsSFF82ZVYh3tL0ehKCKvCe0Wvi8ciIArcncdn0L/wGVeSM3X aYv85YBs14SG+7zMjCj0rcm+Xx41zh4wMGs/dKmBOF5L6eBSb2UvS57QZDKSKb7jEBqW YnQZnZfqzXDevKvT/WTNM83s9lDRmS5JvZr26qlvg6rWPXmQdouKNzvzCTNpH4WJ2lPu zJiJQpf5g9nCDXCKIFFmqd1gVULLBqJ9fdyYqC5xlG3iD1yaF0PiyWJ4irYUtCwQKT4m 8nrw== 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=sln1IsFPWRFtNzDapJfqz9D0UXVcbAOIwCVnS/WVrtY=; b=thoRc0xawXr/fEmo3VeJHtCWMXniGbTt4SRuCDZBSobP7oYEEMkGZmi1AIo23Y6EOc MHz9rqDWQxygycKkloqUKqi94yrCk9B/dEbxxNiYmYiSh8Wn8CsLgNwQAsgk2UP6gikc pt5GNyBql+IU6hrWkycJNpo0aws/kFKnQMZWupo5t9EOvNAx4KqrGRL5zpDQhZFOVQq3 WUspbBANkBjxnvYnO6FIj7inrnO4beLd4LoMljie6NvtDnX2jcWsrMiJSQLMSns5G4+T MW4OiAg+5fetlkhTaZnIttZEUauShD+mHbbnbIXt2dQlitG8sa47CgSlcHh840fTUvQV PWLg== X-Gm-Message-State: AOAM531zdVOEuzpeu/eVpsY+hSWc1lsygZhUNHjIYU0jN9qAx++lBohe uGKEqn+fQmNBucmaAGEFyWUYPA== X-Google-Smtp-Source: ABdhPJwOvPxIbh1o3qPJsaGqkunGlbhgt2Yfji/eep9aSP6iGhmKJbXwgWNt3MCRzqxCCkT92+9UHw== X-Received: by 2002:a05:600c:2317:: with SMTP id 23mr3135313wmo.183.1601038748151; Fri, 25 Sep 2020 05:59:08 -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 18/19] tools/vhost-user-rpmb: allow setting of the write_count Date: Fri, 25 Sep 2020 13:51:46 +0100 Message-Id: <20200925125147.26943-19-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::344; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x344.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) This is mostly useful for testing. Practically all guest operations will probe the write count before any write transaction. Signed-off-by: Alex Benn=C3=A9e --- tools/vhost-user-rpmb/main.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/vhost-user-rpmb/main.c b/tools/vhost-user-rpmb/main.c index 34607ad19429..c798a6f66cd2 100644 --- a/tools/vhost-user-rpmb/main.c +++ b/tools/vhost-user-rpmb/main.c @@ -39,6 +39,7 @@ static gchar *socket_path; static char *flash_path; static char *key_path; +static gint initial_counter; static gint socket_fd =3D -1; static gboolean print_cap; static gboolean verbose; @@ -49,6 +50,7 @@ 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" }, + { "initial-counter", 0, 0, G_OPTION_ARG_INT, &initial_counter, "Set in= itial value of write counter", NULL}, { "key-path", 0, 0, G_OPTION_ARG_FILENAME, &key_path, "Location of per= sistent keyfile", "KEY"}, { "key-set", 0, 0, G_OPTION_ARG_NONE, &key_set, "Is the key already pr= ogrammed", NULL}, { "fd", 0, 0, G_OPTION_ARG_INT, &socket_fd, "Specify the file-descript= or of the backend, incompatible with --socket-path", "FD" }, @@ -797,6 +799,10 @@ int main(int argc, char *argv[]) vrpmb_set_key(&rpmb, key_path); } =20 + if (initial_counter) { + rpmb.write_count =3D initial_counter; + } + if (!socket_path && socket_fd < 0) { g_printerr("Please specify either --fd or --socket-path\n"); exit(EXIT_FAILURE); --=20 2.20.1 From nobody Thu Apr 25 14:33:28 2024 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=1601039130; cv=none; d=zohomail.com; s=zohoarc; b=TPEt/UT1Kl9APi8RxNYMJlsJCpYRqwcQiw/vaU84qu54I4+WkxYYIPoxVwov2PsrHA7qjPr93x/gbnxIw+XeFpDQ9Wmwrci1rRl+NiMS4ZRbq+jERy9x9At/PmVSSJOJr7aCgmKb9nhpEK5Psk6+kdoo85kNNaqI4Cq/j6taPbw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601039130; 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=pVKBS48AbwRPMB8Nsn3vDh4qlhS4C2TzgyypcYvasXA=; b=jJBXTUFiza/gv/KZnk8y9tBUeOl/LEGT1OoSgiKob3EP/YoRhN35kSlJ5GFZ1FdT+F1fTV+TtXBEjoFU3/SJqgtCvJUGNX6hvm7wawKKg/Q0FtLpVSxzTZZGth3gUEmMup5bip0uyLul5I3BWuN26rdcSjdK7zOilDfZU2q4UO4= 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 1601039130549426.45849711015387; Fri, 25 Sep 2020 06:05:30 -0700 (PDT) Received: from localhost ([::1]:46816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLnPl-0007hX-27 for importer@patchew.org; Fri, 25 Sep 2020 09:05:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLnJj-0002aU-VH for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:16 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:42694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kLnJg-0002H4-FG for qemu-devel@nongnu.org; Fri, 25 Sep 2020 08:59:15 -0400 Received: by mail-wr1-x431.google.com with SMTP id c18so3486009wrm.9 for ; Fri, 25 Sep 2020 05:59:11 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id e1sm2891195wrp.49.2020.09.25.05.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2020 05:59:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 064BC1FF7E; Fri, 25 Sep 2020 13:51:50 +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=pVKBS48AbwRPMB8Nsn3vDh4qlhS4C2TzgyypcYvasXA=; b=ZBJZ7pcJqJAVmUAbL4bU66vcIwVRIBqHWOASZ/moE0vV9ZZ33zqzmEXlFz4PpHxyJj Uaz50G84KCnXXDED5db8v/So/HcoT41z/5o6kTlmVpJeGh9K1osiMIDL+9ePs+osyjtw ILIJ4EmKoiyejWgBu8wQq6abQvntQ8CYDjEe2HFSomOfk4gmh26KOujkWs9BaIO1BKUR Z1Uh1k1BlhWT/C+rmkcVZk7X5PcR9R/g/YTXKLN7lFCNJhPdxGR+HfwTM8xnlyqrvzDG a+1tkSxfjFM2zda9K6l23VMm3E+YHLGwoij5h5DI9k3dvIDSp0NyuCjHuEyXrR0ZUmiP c69g== 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=pVKBS48AbwRPMB8Nsn3vDh4qlhS4C2TzgyypcYvasXA=; b=fR5KJ/Cu7kIcb6U5JabxCnHRARqZAXFNnWU2YvtsrIp8mHAWTjExXo3lg03vLcE0mn Im5CKDyJrfB6526d4I4ApURoBMcNoNwCVQ1W9yX8x3jWW3Zr5XfcU9JSMj5j8AmwwVxJ seZXqPH0Dxqc1ru4W3zr6pUvNsE8l7BCkZVfjxFjHCq1P6TPUDpvvdqyoY9Wk4Lz91qK 8zaAQoI7rKmVl5ozYYUziZyu+ybDbiwp+9xGl4wRutYKt7hJCpaQx3kSxwCLE1yCqtvV bCO1spty42A1HGDHgN77kXCQjs0+z92vg0nXPubpoicB298zqihoiPui+QUA8flOG/Su 8AIg== X-Gm-Message-State: AOAM531/SLnR/XthWJHigYxhLZFtlQD6Rl4nf826oJIb4Tl0tk2uNoPQ 18X20V5bN35QkFQE4hY5hARGWQ== X-Google-Smtp-Source: ABdhPJwCqES0abvcUL6qZHv6FfjWwPBI3DLs8hO10nQV8cxdXD+ajQvsKcdNDT3JetUMn+NKAOi/PQ== X-Received: by 2002:a5d:4cc1:: with SMTP id c1mr4416288wrt.122.1601038750650; Fri, 25 Sep 2020 05:59:10 -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 19/19] docs: add a man page for vhost-user-rpmb Date: Fri, 25 Sep 2020 13:51:47 +0100 Message-Id: <20200925125147.26943-20-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::431; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x431.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) Basic usage and example invocation. Signed-off-by: Alex Benn=C3=A9e --- docs/tools/index.rst | 1 + docs/tools/vhost-user-rpmb.rst | 102 +++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 docs/tools/vhost-user-rpmb.rst diff --git a/docs/tools/index.rst b/docs/tools/index.rst index 232ce9f3e463..488784b3bf1f 100644 --- a/docs/tools/index.rst +++ b/docs/tools/index.rst @@ -15,3 +15,4 @@ Contents: qemu-trace-stap virtfs-proxy-helper virtiofsd + vhost-user-rpmb diff --git a/docs/tools/vhost-user-rpmb.rst b/docs/tools/vhost-user-rpmb.rst new file mode 100644 index 000000000000..40d5d3bceb7c --- /dev/null +++ b/docs/tools/vhost-user-rpmb.rst @@ -0,0 +1,102 @@ +QEMU vhost-user-rpmb - rpmb emulation backend +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Synopsis +-------- + +**vhost-user-rpmb** [*OPTIONS*] + +Description +----------- + +This program is a vhost-user backed that emulates a VirtIO Replay +Protected Memory Block device. These are usually special partitions +that are part of a flash device that offer protection against reply +attacks. They are used to store secure information in a way that is +hard to tamper with. + +This program is designed to work with QEMU's ``--device +vhost-user-rpmb-pci`` but should work with any virtual machine +monitor (VMM) that supports vhost-user. See the Examples section +below. + +This program requires a backing store to persist any data programmed +into the device. The spec supports devices up 32Mb in size. For the +daemon this is simply a raw file of the appropriate size. To program +the device it needs to have a key. This can either be programmed by +the guest at the start or come from a key file supplied to the daemon. + +Options +------- + +.. program:: vhost-user-rpmb + +.. option:: -h, --help + + Print help. + +.. option:: -V, --version + + Print version. + +.. option:: -v, --verbose + + Increase verbosity of output + =20 +.. option:: --debug + + Enable debug output. + +.. option:: --socket-path=3DPATH + + Listen on vhost-user UNIX domain socket at PATH. Incompatible with --fd. + +.. option:: --fd=3DFDNUM + + Accept connections from vhost-user UNIX domain socket file descriptor FD= NUM. + The file descriptor must already be listening for connections. + Incompatible with --socket-path. + +.. option:: --flash-path=3DPATH + + Path to the backing store for the flash image, can be up to 32Mb in size. + +.. option:: --key-path=3DPATH + + Path to the backing store for the key of 32 bytes. + =20 +.. option:: --key-set + + Treat the value of key-path as set meaning the key cannot be + reprogrammed by the guest. + +.. option:: --initial-counter=3DN + + Set the initial value of the devices write count. It is + incremented by each write operation.=20 + +Examples +-------- + +The daemon should be started first: + +:: + + host# vhost-user-rpmb --socket-path=3Dvrpmb.sock \ + --flash-path=3Dflash.img \ + --key-path=3Dkey --key-set \ + --initial-counter=3D1234 + +The QEMU invocation needs to create a chardev socket the device can +use to communicate as well as share the guests memory over a memfd. + +:: + + host# qemu-system \ + -chardev socket,path=3Dvrpmb.sock,id=3Dvrpmb \ + -device vhost-user-rpmb-pci,chardev=3Dvrpmb,id=3Drpmb \ + -m 4096 \ + -object memory-backend-file,id=3Dmem,size=3D4G,mem-path=3D/dev/shm,s= hare=3Don \ + -numa node,memdev=3Dmem \ + ... + --=20 2.20.1