From patchwork Fri Apr 19 15:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 790211 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp1153062wrm; Fri, 19 Apr 2024 09:08:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU93Gj0EUC8vbeAERh4MJFqSyH8smbJ/HVuuQoyti4HsXlFd5usX9ID+o4TH0GcEYlvV5iB6h5Tihq13GdfpDzi X-Google-Smtp-Source: AGHT+IHg9326dg8qTGrzPhfgFWPN4QloyiL5ibg1P6SP0iUVh8VXmDJ3GcmbSJkwgZxc/4tEnMIk X-Received: by 2002:a05:622a:387:b0:437:9877:333 with SMTP id j7-20020a05622a038700b0043798770333mr3038996qtx.35.1713542895627; Fri, 19 Apr 2024 09:08:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713542895; cv=none; d=google.com; s=arc-20160816; b=jwZ7y5tXvSkeq/r13V8VnyquaS/R/cm/v755sZiHQFI3P+aKaxm2WYCd1iTndSaN6Y RLCe+6oCM8ErDygehsdHFKl7Rj1M8343Mt6EhPIMtX6HjUfvSusXI9KZmOBvUDpobvv+ 47MdMf2Uao0i1CBI6F7zqdrKham0Da9nsvUdxb86Qqep/MBnCmxDXJZ00YxiErO8/sC+ dGeMOe2pgjCjkW6yy5Sq3D0oy+E0jRaJm4cihzIYcH+FEyKWIYiwMHIrMSrvXitduygO xfrt50OLMFOKIjUm+a8gszowrCnmYN2KZYzuXSDhWJ8I8P7r7tV/7osxZnpPqx9TJlew SqYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=blRxAD//qWk7awT/WiqSSIKjaOzzlNxFM9Csitf6cJ0=; fh=du1bhGUEapLslSSysnsplDKUhMDNOM40ZLUnDPV66U8=; b=AsWW3PagOoBOB7h4622QV/4Bv+M5xdM5NCQKkogkmoPa17Pf8esg7ixbDLO+wfygt0 KF+mfu6cy1UvGgldlwMDvLyYYDc8n18ep4tolrdBiqMuhHY57gTgvC23hadrkT/309ht 21w4KsEVz1ata3C6n6drweA7z5RS1X2nXEZZiJ8vKGQeDTKxIX5lXiJeoPMnrwYH8q8w 8L0/J23sKRECDi6wgQKu4JcRJRmQR707j1tbp8LBBloTifB3SYYzdPj9ZjwuOiWDmjp/ l/xDAnNb74wQpK71D9+erx32JMTwvVPPJOEVn78ZsJCahmycu3IcjtjFTomfC6EHXFBP mZLA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EXUi66CP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fg19-20020a05622a581300b0043461a30dc8si4582403qtb.320.2024.04.19.09.08.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2024 09:08:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EXUi66CP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rxqgR-0002Ky-Vr; Fri, 19 Apr 2024 12:01:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rxqef-0001Dj-Qf for qemu-devel@nongnu.org; Fri, 19 Apr 2024 12:00:02 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rxqeZ-00017E-O5 for qemu-devel@nongnu.org; Fri, 19 Apr 2024 12:00:01 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-34a32ba1962so1148564f8f.2 for ; Fri, 19 Apr 2024 08:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1713542394; x=1714147194; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=blRxAD//qWk7awT/WiqSSIKjaOzzlNxFM9Csitf6cJ0=; b=EXUi66CPIKd4xJAss7y15jFi5UVbWQIRHS4EGuT/yY7V8XIL++i4zPlrgytOg63ajW saccqyxKcK56vWdVi8jCFvCqNRId4/pz6bTJw9kevivzMl5WiJS0u+Rgw2FGEzMPeGNk cp1q5UjYLI9Y1GsX22XbVAp8kqX4hKT1lyaUU+VNW5fE3q9ZVBeG8OliER9PH2+bgm1k 7NDqrTdQNXW2UE1zW99i74cCpA9qY6dEHL6m55D/8T5/Fi28eePEGOldxsMYVHo5exVR 6cXxr0YGcCR63aLiryqdBjiNuyNB8zyThA9ayO9ZAqWZrAH2dGM7Bs2vhMhfjSWHaxiv 2tnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713542394; x=1714147194; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=blRxAD//qWk7awT/WiqSSIKjaOzzlNxFM9Csitf6cJ0=; b=KW0g93BmRxPBA2VQ4+cj08nL5DceU3MK4sG6zEYbY7MqN9QzyGjar6sWJxZ3VTmPRR Yvn6fLU5MawdKxEcXwfqsHn942M6zZOU/KVice/TfyagyDe5DdJn3hSubanzUZwwMz77 kCyYJnBtrJDyBvWUHM8IQLngptaGVprkkeF4d+mmOrkRIFgySrWXHb2nA9wsPCRBggqe gB4KeBhJM+uSzpud3SXVqZhwbaIyM3LJEhe0FCxMVnJMcYwEaSjuwbp50JjyH6L/vk9j +WXiHjUCeTMlOba4AsCYxNYsKd9D3hGyr8mi0CLwxoEWaOpadypP55kGVkC9JwbsCVDn xKtg== X-Forwarded-Encrypted: i=1; AJvYcCXtG7yl/E/w+ZFEuGpKdm2TcVPthCtDDEqWX5oMT1pvua5y1KFIWPuSPjT/6yUlOzFbprXIKFYaA3G9vYzl+ImQVqype5c= X-Gm-Message-State: AOJu0Yz3lWGSDpdh5s3cI3GWqlVP1Hw3LOnFxAJ6EOyf83g0QtI2SXLt SH8sOzYFadN5wBf50TIOoGeJG+lt7HRA0ot/ofTZiitv37EKbni41dG+ifA2gNc= X-Received: by 2002:a5d:4a81:0:b0:343:8d1b:b12d with SMTP id o1-20020a5d4a81000000b003438d1bb12dmr1452401wrq.46.1713542394163; Fri, 19 Apr 2024 08:59:54 -0700 (PDT) Received: from localhost.localdomain ([2.221.137.100]) by smtp.gmail.com with ESMTPSA id p13-20020adfe60d000000b00349b73143e7sm4793089wrm.75.2024.04.19.08.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 08:59:53 -0700 (PDT) From: Jean-Philippe Brucker To: peter.maydell@linaro.org, richard.henderson@linaro.org Cc: philmd@linaro.org, pbonzini@redhat.com, alex.bennee@linaro.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org, Jean-Philippe Brucker Subject: [PATCH v2 11/22] hw/core/loader: Add ROM loader notifier Date: Fri, 19 Apr 2024 16:56:59 +0100 Message-ID: <20240419155709.318866-13-jean-philippe@linaro.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240419155709.318866-2-jean-philippe@linaro.org> References: <20240419155709.318866-2-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x429.google.com 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add a function to register a notifier, that is invoked after a ROM gets loaded into guest memory. It will be used by Arm confidential guest support, in order to register all blobs loaded into memory with KVM, so that their content is part of the initial VM measurement and contribute to the guest attestation. Signed-off-by: Jean-Philippe Brucker --- v1->v2: new --- include/hw/loader.h | 15 +++++++++++++++ hw/core/loader.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/hw/loader.h b/include/hw/loader.h index 8685e27334..79fab25dd9 100644 --- a/include/hw/loader.h +++ b/include/hw/loader.h @@ -356,6 +356,21 @@ void hmp_info_roms(Monitor *mon, const QDict *qdict); ssize_t rom_add_vga(const char *file); ssize_t rom_add_option(const char *file, int32_t bootindex); +typedef struct RomLoaderNotify { + /* Parameters passed to rom_add_blob() */ + hwaddr addr; + size_t len; + size_t max_len; +} RomLoaderNotify; + +/** + * rom_add_load_notifier - Add a notifier for loaded images + * + * Add a notifier that will be invoked with a RomLoaderNotify structure for each + * blob loaded into guest memory, after the blob is loaded. + */ +void rom_add_load_notifier(Notifier *notifier); + /* This is the usual maximum in uboot, so if a uImage overflows this, it would * overflow on real hardware too. */ #define UBOOT_MAX_GUNZIP_BYTES (64 << 20) diff --git a/hw/core/loader.c b/hw/core/loader.c index b8e52f3fb0..4bd236cf89 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -67,6 +67,8 @@ #include static int roms_loaded; +static NotifierList rom_loader_notifier = + NOTIFIER_LIST_INITIALIZER(rom_loader_notifier); /* return the size or -1 if error */ int64_t get_image_size(const char *filename) @@ -1209,6 +1211,11 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len, return mr; } +void rom_add_load_notifier(Notifier *notifier) +{ + notifier_list_add(&rom_loader_notifier, notifier); +} + /* This function is specific for elf program because we don't need to allocate * all the rom. We just allocate the first part and the rest is just zeros. This * is why romsize and datasize are different. Also, this function takes its own @@ -1250,6 +1257,7 @@ ssize_t rom_add_option(const char *file, int32_t bootindex) static void rom_reset(void *unused) { Rom *rom; + RomLoaderNotify notify; QTAILQ_FOREACH(rom, &roms, next) { if (rom->fw_file) { @@ -1298,6 +1306,13 @@ static void rom_reset(void *unused) cpu_flush_icache_range(rom->addr, rom->datasize); trace_loader_write_rom(rom->name, rom->addr, rom->datasize, rom->isrom); + + notify = (RomLoaderNotify) { + .addr = rom->addr, + .len = rom->datasize, + .max_len = rom->romsize, + }; + notifier_list_notify(&rom_loader_notifier, ¬ify); } }