From nobody Sat Apr 27 15:20:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.43 as permitted sender) client-ip=209.85.128.43; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f43.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail(p=quarantine dis=quarantine) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1642637571; cv=none; d=zohomail.com; s=zohoarc; b=KTed4et1VUf+2lwROD3W7/YkJljZIWG2+januQvI9cfFDcATr1d/CYr2w6n0jf14QFQZD1orqz89JLBjys+ilKXBPpqube67TTmyNn2KR2/LRb+dH8vN0Ei7VUhBG1fu0Us0SzfQAJByO6+rCmviSFFZacltdAEy37NE1hjjn94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642637571; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NsyFyyrMhaIGsZfTZhTpF24jgdat+4WKXL7TSaiz5ms=; b=abSYlkhkOzOXx3yqvbrOgbpcEcVYzVGdm6eMs3MNWTCuioTRY9r+po9/kZEpUAY5FIyBI38ucf9mekdRqH6txfO7fI62YHZdXzcNSSeeo3+PYg7vJ0F9HaXnz89bTFcmqPh8m5bmuCwyjxDQPIvCPOMH3qFiG/6RzbMBi+zqnGI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by mx.zohomail.com with SMTPS id 1642637571408330.13601981893885; Wed, 19 Jan 2022 16:12:51 -0800 (PST) Received: by mail-wm1-f43.google.com with SMTP id p18so8412500wmg.4 for ; Wed, 19 Jan 2022 16:12:50 -0800 (PST) Return-Path: Return-Path: Received: from nuc.. (154.red-83-50-83.dynamicip.rima-tde.net. [83.50.83.154]) by smtp.gmail.com with ESMTPSA id j18sm1009424wmq.26.2022.01.19.16.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 16:12:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NsyFyyrMhaIGsZfTZhTpF24jgdat+4WKXL7TSaiz5ms=; b=G19Nd2O+0ty8aQSyQF59TUheRT8KHljTKOIkfuZcR57NqQ1ImKkNFJILI0T65K9J+U HInZp1zF3lAFphrA6/JFBFOPmSmKJjdBwRUPBQJV3EUBB6Rs+U578OZIGT4u2j0Hn3io VtugRbIFRZdmyNt2sn67vLIQDx5HOzKKfWgpJ3T4ESjlHEDPgFxuWDTpuegBm3gFEQez e4Nei+kvnWIt/rG8lwgwk/N9rR7c4KFRX/3xpsfZ/0ALMpRIGGswOeSww5JbgxBYYREK 9sUqBJNu+E1Pg0X7I6Ne0DylWefbbkllBk+gG5zbf1S+6ZT6j9VjIg6+c2iD+Xa9nMGb TFrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NsyFyyrMhaIGsZfTZhTpF24jgdat+4WKXL7TSaiz5ms=; b=69bRinkyrZMDijXvIz6y/v5/vbDGh0GrDTgVqq+qZXP8JPI6wV9lSs4lsj60jUgwTj w/LlZWnUClSoiWViF+emXOUTL5uWlRL+1GkqrToMWY/emhtc2nLBBU1C9pUiYmpS8+4M KlmTpJJSS41zoEMNV6+Bad2lDL05+me/hUK9Y0RJV77dhbLKAr1DsO80Yg4m9znqMO1b UUpkgJs2+c7ePy3ySyeTghauoOdlxZ/7ASFrB5XvEt/vOb4X+kOuHNefZMVBq8wBRFwH 6Rnzrlvv87j5zXl3VLAZL1ZnAUQ6cyYxAYXZ+J3WqIKCWy8XXqvS0kC1pG5Ro2DgrQAn LgOA== X-Gm-Message-State: AOAM530AbfhKofIaDsPeASb4PpXmy2MZ5g1wPK8FVqosOvo1w4Fxg7im 71HvaJh2EMLu8lhaI26uQkWYXWMGECc= X-Google-Smtp-Source: ABdhPJzSnwZ8yF3YrG4iDse8l0BIV2clkvtB0qGue5poHX/szF2ovuGgWQABKLeWYjX6OErYFh1Rlw== X-Received: by 2002:a5d:5848:: with SMTP id i8mr20250275wrf.146.1642637569582; Wed, 19 Jan 2022 16:12:49 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefan Berger , Alex Williamson , Eric Auger , Stefan Berger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 1/2] tpm: CRB: Use ram_device for "tpm-crb-cmd" region Date: Thu, 20 Jan 2022 01:12:41 +0100 Message-Id: <20220120001242.230082-2-f4bug@amsat.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220120001242.230082-1-f4bug@amsat.org> References: <20220120001242.230082-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1642637572191100001 From: Eric Auger Representing the CRB cmd/response buffer as a standard RAM region causes some trouble when the device is used with VFIO. Indeed VFIO attempts to DMA_MAP this region as usual RAM but this latter does not have a valid page size alignment causing such an error report: "vfio_listener_region_add received unaligned region". To allow VFIO to detect that failing dma mapping this region is not an issue, let's use a ram_device memory region type instead. Signed-off-by: Eric Auger Tested-by: Stefan Berger Acked-by: Stefan Berger [PMD: Keep tpm_crb.c in meson's softmmu_ss] Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/tpm/tpm_crb.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c index 58ebd1469c3..be0884ea603 100644 --- a/hw/tpm/tpm_crb.c +++ b/hw/tpm/tpm_crb.c @@ -25,6 +25,7 @@ #include "sysemu/tpm_backend.h" #include "sysemu/tpm_util.h" #include "sysemu/reset.h" +#include "exec/cpu-common.h" #include "tpm_prop.h" #include "tpm_ppi.h" #include "trace.h" @@ -43,6 +44,7 @@ struct CRBState { =20 bool ppi_enabled; TPMPPI ppi; + uint8_t *crb_cmd_buf; }; typedef struct CRBState CRBState; =20 @@ -291,10 +293,14 @@ static void tpm_crb_realize(DeviceState *dev, Error *= *errp) return; } =20 + s->crb_cmd_buf =3D qemu_memalign(qemu_real_host_page_size, + HOST_PAGE_ALIGN(CRB_CTRL_CMD_SIZE)); + memory_region_init_io(&s->mmio, OBJECT(s), &tpm_crb_memory_ops, s, "tpm-crb-mmio", sizeof(s->regs)); - memory_region_init_ram(&s->cmdmem, OBJECT(s), - "tpm-crb-cmd", CRB_CTRL_CMD_SIZE, errp); + memory_region_init_ram_device_ptr(&s->cmdmem, OBJECT(s), "tpm-crb-cmd", + CRB_CTRL_CMD_SIZE, s->crb_cmd_buf); + vmstate_register_ram(&s->cmdmem, DEVICE(s)); =20 memory_region_add_subregion(get_system_memory(), TPM_CRB_ADDR_BASE, &s->mmio); @@ -309,12 +315,24 @@ static void tpm_crb_realize(DeviceState *dev, Error *= *errp) qemu_register_reset(tpm_crb_reset, dev); } =20 +static void tpm_crb_unrealize(DeviceState *dev) +{ + CRBState *s =3D CRB(dev); + + qemu_vfree(s->crb_cmd_buf); + + if (s->ppi_enabled) { + qemu_vfree(s->ppi.buf); + } +} + static void tpm_crb_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); TPMIfClass *tc =3D TPM_IF_CLASS(klass); =20 dc->realize =3D tpm_crb_realize; + dc->unrealize =3D tpm_crb_unrealize; device_class_set_props(dc, tpm_crb_properties); dc->vmsd =3D &vmstate_tpm_crb; dc->user_creatable =3D true; --=20 2.34.1 From nobody Sat Apr 27 15:20:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) client-ip=209.85.128.48; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f48.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail(p=quarantine dis=quarantine) header.from=amsat.org ARC-Seal: i=1; a=rsa-sha256; t=1642637576; cv=none; d=zohomail.com; s=zohoarc; b=C16JsoJvguweNNPTY0vbQDq+y1KXdUtw83h//ow6fnKn5aXbuFMu4WL4NBx5DVWTZtmJbdt3tS+Ps6CGGAjaxijhF52GrnkIFUBJwcHn6vV16pcqS8EwuWLtRG4HC3wG6ayBsOlyv6qgs9EwiYz0n6Bj3cuzmXwA9hL5YXrNGA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642637576; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gEGYgTjbnr/i5w2mvdp+uG1/Mmv2kSr/Q4Dwa+03rII=; b=PH3Jai/QGoLSSLXvhgdUJlCTmGesrmlyQo4pdm9KHvNZeRCDzedNr9ERjM6xuSho5eB4cBdKN9vs0L0/WJ+tZRSsvrnyWc5VDep5C+BcZNhenST+3QEHSFUkaELtIrA0/h1uOhnjw7+CKa9gmKsMk4mPhABkIIGfppDbYs6FTpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com; dmarc=fail header.from= (p=quarantine dis=quarantine) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mx.zohomail.com with SMTPS id 1642637576133400.25437472345175; Wed, 19 Jan 2022 16:12:56 -0800 (PST) Received: by mail-wm1-f48.google.com with SMTP id q141-20020a1ca793000000b00347b48dfb53so9593460wme.0 for ; Wed, 19 Jan 2022 16:12:55 -0800 (PST) Return-Path: Return-Path: Received: from nuc.. (154.red-83-50-83.dynamicip.rima-tde.net. [83.50.83.154]) by smtp.gmail.com with ESMTPSA id p2sm838879wmc.33.2022.01.19.16.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jan 2022 16:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gEGYgTjbnr/i5w2mvdp+uG1/Mmv2kSr/Q4Dwa+03rII=; b=KZ/K9x1/YSFLYw+6mgLOE45htFg6sPlXemD24R+CnXoMA1KI9sOeqgx0FHy0OmSoTD uv8kmaeu/SLOsJsBMPXu2cofvR9f0Rt1zeLNHRUlBsY/teMpJXQcw9XUa2hDre+V/ysg uafUxqVbD90PN9iEMNikpCSpHtWA1T0nXWbCN0qYtJu6gcRu2E/GG45C2BB0S4m80Uuq Ih4HgX3fF025NZ/HsYU5E0TlacvGgBorC3W8kANmAUl6i8/kUOC+hnj4RFia4CEt11+l kjsABrekDzKi6b2TlL4Uedi796QoQQC33TBkamevqY4i6M/KgdX4qLTQNnS5KMzSK3rp D8hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=gEGYgTjbnr/i5w2mvdp+uG1/Mmv2kSr/Q4Dwa+03rII=; b=I1W91S8t21KS73uFbbgExFeL3gh4dVtK8gVZik0EEXWqyRRzvIBE2A9I7d0Lffrj8M ui4qRYOD+K6S1ZTkgqavHOiK2uuE9ttRef8YW5XVOdTusEHc6iwQ70xAPLtPX19WQORO l44gn24kFXa3253xec42qL5xAvsxZpkqm/qAJGVKGpkPOdLeEuT3zOvIm2blpDTdpRAx Y9BAYQB4JPVoFjdGZYKE6IQCbI1Qyv2lflK9eZA98IdkYlicwRWuz1/XIt6PBdBqvEL+ Y/Iu3gmMqtHVZuyjK89EySeLC5CyG3RnG87MF4Y2tBZnGdGY4nHKsh6pSbD5UAH5nLSR lXAA== X-Gm-Message-State: AOAM530djt2NG8xS5QrB2HdfOp36wEeVcMscMVDrSd1H8zrJdZu8SRVM nLeXEgH1dIu3+xznNYm2xwY= X-Google-Smtp-Source: ABdhPJxhFY1GPaVywsmTrmLnPkPLA6uPhQ8jjneYJda1w5VFwXYy2AZglcUV9IT/hlWGtRQldY1bUQ== X-Received: by 2002:a5d:6d45:: with SMTP id k5mr29425232wri.397.1642637574410; Wed, 19 Jan 2022 16:12:54 -0800 (PST) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefan Berger , Alex Williamson , Eric Auger , Stefan Berger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 2/2] hw/vfio/common: Silence ram device offset alignment error traces Date: Thu, 20 Jan 2022 01:12:42 +0100 Message-Id: <20220120001242.230082-3-f4bug@amsat.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220120001242.230082-1-f4bug@amsat.org> References: <20220120001242.230082-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1642637576837100001 From: Eric Auger Failing to DMA MAP a ram_device should not cause an error message. This is currently happening with the TPM CRB command region and this is causing confusion. We may want to keep the trace for debug purpose though. Signed-off-by: Eric Auger Tested-by: Stefan Berger Acked-by: Alex Williamson Acked-by: Stefan Berger Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/vfio/common.c | 15 ++++++++++++++- hw/vfio/trace-events | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 080046e3f51..9caa560b078 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -884,7 +884,20 @@ static void vfio_listener_region_add(MemoryListener *l= istener, if (unlikely((section->offset_within_address_space & ~qemu_real_host_page_mask) !=3D (section->offset_within_region & ~qemu_real_host_page_mas= k))) { - error_report("%s received unaligned region", __func__); + if (memory_region_is_ram_device(section->mr)) { /* just debug purp= ose */ + trace_vfio_listener_region_add_bad_offset_alignment( + memory_region_name(section->mr), + section->offset_within_address_space, + section->offset_within_region, qemu_real_host_page_size); + } else { /* error case we don't want to be fatal */ + error_report("%s received unaligned region %s iova=3D0x%"PRIx64 + " offset_within_region=3D0x%"PRIx64 + " qemu_real_host_page_mask=3D0x%"PRIx64, + __func__, memory_region_name(section->mr), + section->offset_within_address_space, + section->offset_within_region, + qemu_real_host_page_mask); + } return; } =20 diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 0ef1b5f4a65..ccd9d7610d6 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -100,6 +100,7 @@ vfio_listener_region_add_skip(uint64_t start, uint64_t = end) "SKIPPING region_add vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to = liobn fd %d" vfio_listener_region_add_iommu(uint64_t start, uint64_t end) "region_add [= iommu] 0x%"PRIx64" - 0x%"PRIx64 vfio_listener_region_add_ram(uint64_t iova_start, uint64_t iova_end, void = *vaddr) "region_add [ram] 0x%"PRIx64" - 0x%"PRIx64" [%p]" +vfio_listener_region_add_bad_offset_alignment(const char *name, uint64_t i= ova, uint64_t offset_within_region, uint64_t page_size) "Region \"%s\" @0x%= "PRIx64", offset_within_region=3D0x%"PRIx64", qemu_real_host_page_mask=3D0x= %"PRIx64 " cannot be mapped for DMA" vfio_listener_region_add_no_dma_map(const char *name, uint64_t iova, uint6= 4_t size, uint64_t page_size) "Region \"%s\" 0x%"PRIx64" size=3D0x%"PRIx64"= is not aligned to 0x%"PRIx64" and cannot be mapped for DMA" vfio_listener_region_del_skip(uint64_t start, uint64_t end) "SKIPPING regi= on_del 0x%"PRIx64" - 0x%"PRIx64 vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRI= x64" - 0x%"PRIx64 --=20 2.34.1