From nobody Fri May 17 22:17:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651843664; cv=none; d=zohomail.com; s=zohoarc; b=Yl5my++/y2JzTS+aZtvdW0h7YwRQDxzws7c0992dxUZpyaf0I/PPGCd4Uw3RjlPiS+VOCzGNa/WgFy+Tj6bKG/LPXBLPcQaksu0vF5+8odEN7B2JfhX3xahyjsul7Le9dFCz5fErko32BTlMxSbkFQpZF7G9ti/UYdjxwbQpRpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651843664; h=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=rZ+mtQ/yxeOqRCkBzqGUVFxvyihd4uT2Lefl+rkpUx0=; b=lSKhtAQU9DX3WdE0agsfQ+jG87c4UliE0EcwNdkHV7Cp0bUA785eP8prX7a+5f/ZCd1V3geff6nVhhW7fNmdtZTqMSPIBt+RLAWPIUscxeMbhZ5k6N9nIJu6J1myYPH0noaVXRGvFSFMLdYTkPM4HKNsKg4AqZDg4v37imqPqR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651843664115443.08313350148535; Fri, 6 May 2022 06:27:44 -0700 (PDT) Received: from localhost ([::1]:50224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmxzi-0006MK-Im for importer@patchew.org; Fri, 06 May 2022 09:27:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmxxU-0004oV-HW for qemu-devel@nongnu.org; Fri, 06 May 2022 09:25:24 -0400 Received: from us-smtp-delivery-74.mimecast.com ([170.10.133.74]:56328) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmxxR-0001Xs-Am for qemu-devel@nongnu.org; Fri, 06 May 2022 09:25:23 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-h4xLOiqOOd2ZSOpOoc294Q-1; Fri, 06 May 2022 09:25:19 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E6F5A2999B50; Fri, 6 May 2022 13:25:18 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84DDC403156; Fri, 6 May 2022 13:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651843520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rZ+mtQ/yxeOqRCkBzqGUVFxvyihd4uT2Lefl+rkpUx0=; b=HxcySoe2pWG11ApT3HbNs3etAQ/XrvgSwB3V1b9a2oMJCBsW6Z9MKdb4CaXRifP9jD7dsX G8Nt0E1v2IK8YA0IghgBwh+V6+GyC466vuYPXG8rfFwLEQrTGvtwYOboCjOXvuGZgoS4sT wc0FUsBEFmvQbWxeH0ejlP3t6tex6Ms= X-MC-Unique: h4xLOiqOOd2ZSOpOoc294Q-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, alex.williamson@redhat.com Cc: stefanb@linux.vnet.ibm.com, cohuck@redhat.com, f4bug@amsat.org Subject: [PATCH v5 1/2] sysemu: tpm: Add a stub function for TPM_IS_CRB Date: Fri, 6 May 2022 15:25:09 +0200 Message-Id: <20220506132510.1847942-2-eric.auger@redhat.com> In-Reply-To: <20220506132510.1847942-1-eric.auger@redhat.com> References: <20220506132510.1847942-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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=170.10.133.74; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-74.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651843664754100002 Content-Type: text/plain; charset="utf-8" In a subsequent patch, VFIO will need to recognize if a memory region owner is a TPM CRB device. Hence VFIO needs to use TPM_IS_CRB() even if CONFIG_TPM is unset. So let's add a stub function. Signed-off-by: Eric Auger Suggested-by: Cornelia Huck Reviewed-by: Stefan Berger --- include/sysemu/tpm.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/sysemu/tpm.h b/include/sysemu/tpm.h index 68b2206463c..fb40e30ff60 100644 --- a/include/sysemu/tpm.h +++ b/include/sysemu/tpm.h @@ -80,6 +80,12 @@ static inline TPMVersion tpm_get_version(TPMIf *ti) #define tpm_init() (0) #define tpm_cleanup() =20 +/* needed for an alignment check in non-tpm code */ +static inline Object *TPM_IS_CRB(Object *obj) +{ + return NULL; +} + #endif /* CONFIG_TPM */ =20 #endif /* QEMU_TPM_H */ --=20 2.35.1 From nobody Fri May 17 22:17:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1651843747; cv=none; d=zohomail.com; s=zohoarc; b=ciC9q32yyVzC82D4fbhIM4wBnnSoyYR98Ip5abmvVU019byRky64+6sei5l+grJ9mRl7pm2qPSHi28Ujb5a8V+TI/LrSzFllkuTG1vd2aX3c2ui7wiklA7UPdqTHmWEwctNts0LpbKP3PdcZ0hBNgzfqmcJ5fPDTWUhR9zwDbcw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651843747; 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=0utDo+cRrfBoun+vTR1rptcNQEwajUCmaZuqjuiYvLU=; b=XkP1hUbKc7XbJ4z+P8Qcn5HoYVlC+CiS/nkiChNSKJs44dBpoRhzaYdg/F5dIt5ZzHdzpMXL76w15WDSM6Go35iZIZI+h00W6CmVy48Mgrmenja1v0RdvVpIx6H0p3OeRvUnOMXru9FibkKEUc+CbBRCGS9CX7PP/3iWabkybbc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651843747071692.1722009606929; Fri, 6 May 2022 06:29:07 -0700 (PDT) Received: from localhost ([::1]:53444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nmy14-0000Ax-3y for importer@patchew.org; Fri, 06 May 2022 09:29:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmxxj-0005Ah-Gn for qemu-devel@nongnu.org; Fri, 06 May 2022 09:25:39 -0400 Received: from us-smtp-delivery-74.mimecast.com ([170.10.129.74]:39572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nmxxh-0001Zp-RH for qemu-devel@nongnu.org; Fri, 06 May 2022 09:25:39 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517-kiCb8rBiOhiY80PAgiovOA-1; Fri, 06 May 2022 09:25:36 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 95EEB2999B50; Fri, 6 May 2022 13:25:20 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A5ED403156; Fri, 6 May 2022 13:25:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651843537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0utDo+cRrfBoun+vTR1rptcNQEwajUCmaZuqjuiYvLU=; b=CUY/si04JZHtpLhOU3Blm7yHb7levRUI5+Mpu7jw9W16OeZJHbU64Bm9zxFualT4F42jlZ m6GrsVgbDNg/9ljcd29Zm+0u3k8rp6kMyDsurZaiI4ZLGuoexutz0IHd98j0eVTUNPv2fF me/PX8Hv3RSvoZAVNcDdf9Z9A8huzXw= X-MC-Unique: kiCb8rBiOhiY80PAgiovOA-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, alex.williamson@redhat.com Cc: stefanb@linux.vnet.ibm.com, cohuck@redhat.com, f4bug@amsat.org Subject: [PATCH v5 2/2] vfio/common: remove spurious tpm-crb-cmd misalignment warning Date: Fri, 6 May 2022 15:25:10 +0200 Message-Id: <20220506132510.1847942-3-eric.auger@redhat.com> In-Reply-To: <20220506132510.1847942-1-eric.auger@redhat.com> References: <20220506132510.1847942-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 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=170.10.129.74; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-74.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651843747944100001 The CRB command buffer currently is a RAM MemoryRegion and given its base address alignment, it causes an error report on vfio_listener_region_add(). This region could have been a RAM device region, easing the detection of such safe situation but this option was not well received. So let's add a helper function that uses the memory region owner type to detect the situation is safe wrt the assignment. Other device types can be checked here if such kind of problem occurs again. Signed-off-by: Eric Auger Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Berger Reviewed-by: Cornelia Huck --- hw/vfio/common.c | 27 ++++++++++++++++++++++++++- hw/vfio/trace-events | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 2b1f78fdfae..f6b9bb6d718 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -40,6 +40,7 @@ #include "trace.h" #include "qapi/error.h" #include "migration/migration.h" +#include "sysemu/tpm.h" =20 VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); @@ -861,6 +862,22 @@ static void vfio_unregister_ram_discard_listener(VFIOC= ontainer *container, g_free(vrdl); } =20 +static bool vfio_known_safe_misalignment(MemoryRegionSection *section) +{ + MemoryRegion *mr =3D section->mr; + + if (!TPM_IS_CRB(mr->owner)) { + return false; + } + + /* this is a known safe misaligned region, just trace for debug purpos= e */ + trace_vfio_known_safe_misalignment(memory_region_name(mr), + section->offset_within_address_spac= e, + section->offset_within_region, + qemu_real_host_page_size()); + return true; +} + static void vfio_listener_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -884,7 +901,15 @@ 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 (!vfio_known_safe_misalignment(section)) { + error_report("%s received unaligned region %s iova=3D0x%"PRIx64 + " offset_within_region=3D0x%"PRIx64 + " qemu_real_host_page_size=3D0x%"PRIxPTR, + __func__, memory_region_name(section->mr), + section->offset_within_address_space, + section->offset_within_region, + qemu_real_host_page_size()); + } return; } =20 diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 0ef1b5f4a65..582882db91c 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_known_safe_misalignment(const char *name, uint64_t iova, uint64_t off= set_within_region, uintptr_t page_size) "Region \"%s\" iova=3D0x%"PRIx64" o= ffset_within_region=3D0x%"PRIx64" qemu_real_host_page_size=3D0x%"PRIxPTR ":= 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.35.1