From nobody Tue Jul 15 06:20:09 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1678154737; cv=none; d=zohomail.com; s=zohoarc; b=UYBMCN1C5FoPvh67qxwUq6pxWQ6GrDfptKYLb0NfLEPMn5CuFmsmxUC+9+Wtj/VZMYcc0dz20+avBQegTVtZiARK+KWPZmNnxskbEBLP1BU4e+gsUUCCMuBj1KiBQeaAAeAKVXusQaP8gKJ4h59oAppTS1NTg02NstcX6pcMdDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678154737; 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=U424iuqvq3TR9AV41TeI7ouo9ejdeHYzTj2iwoghSbo=; b=A9nXoG+7//8YVgR1GNWPFESsgMije2vtvkfztdbp0ou2PrUHXKSu6U6rPYGRrjwjVCZEx9yCe0QnSt8VmaCkLXYdLFLkrK+q5YRv53Bfu749v4KDYQOawtqyfd/LAkwnlWjXXA8GHIvJZXkr5Low8QvjX8OleTOQofNCbUA1F68= 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+importer2=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 1678154737378936.639618092435; Mon, 6 Mar 2023 18:05:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZMfu-0006s1-Ia; Mon, 06 Mar 2023 21:03:34 -0500 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 1pZMfs-0006rC-A1 for qemu-devel@nongnu.org; Mon, 06 Mar 2023 21:03:32 -0500 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZMfo-0004wJ-KV for qemu-devel@nongnu.org; Mon, 06 Mar 2023 21:03:31 -0500 Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 326NxYsM030050; Tue, 7 Mar 2023 02:03:27 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3p418xvfe3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 07 Mar 2023 02:03:27 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 3271UTZv038062; Tue, 7 Mar 2023 02:03:25 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3p4txdubsf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 07 Mar 2023 02:03:25 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3272356A016763; Tue, 7 Mar 2023 02:03:25 GMT Received: from joaomart-mac.uk.oracle.com (dhcp-10-175-187-101.vpn.oracle.com [10.175.187.101]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3p4txdubf4-7; Tue, 07 Mar 2023 02:03:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2022-7-12; bh=U424iuqvq3TR9AV41TeI7ouo9ejdeHYzTj2iwoghSbo=; b=UlIaSMpX8gHQsTMitBCVmC8c5KGNc7h26sOFZYuxNb+LCO12UgMrO+gNu+sdVKlMW0Iq iDunWdJVVLv9DmL/96kfdx35Jy+zrAzebFW/WMgSLBg0jCRtr2F7G0JSY9qAjW1Xa7KK 9MSpfNuZ99cpkW1ETfHU6M1V9NRUMhD9p1C2LcYKBv8VYCsXW6uahQoxknSIr3VdIXz+ gSaMyZp7oEG0sRIrb6YMC6XQ5p3RrzVCwGFtGFBCG9PTubNN8YYEtkjUAOy4dLXNow5e rJHZNPlUduTZFmRj1107pKVHyXtBiz9uxE26ngRMLz7hLGVYKb1aZ5SxTq4L7sx/7Czn Tg== From: Joao Martins To: qemu-devel@nongnu.org Cc: Alex Williamson , Cedric Le Goater , Yishai Hadas , Jason Gunthorpe , Maor Gottlieb , Kirti Wankhede , Tarun Gupta , Avihai Horon , Joao Martins Subject: [PATCH v4 06/14] vfio/common: Consolidate skip/invalid section into helper Date: Tue, 7 Mar 2023 02:02:50 +0000 Message-Id: <20230307020258.58215-7-joao.m.martins@oracle.com> In-Reply-To: <20230307020258.58215-1-joao.m.martins@oracle.com> References: <20230307020258.58215-1-joao.m.martins@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-06_14,2023-03-06_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=641 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303070016 X-Proofpoint-GUID: PV3J8wcV388D5fSPhlNIQMdn5BLiLfZ- X-Proofpoint-ORIG-GUID: PV3J8wcV388D5fSPhlNIQMdn5BLiLfZ- 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.220.165.32; envelope-from=joao.m.martins@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1678154738386100001 The checks are replicated against region_add and region_del and will be soon added in another memory listener dedicated for dirty tracking. Move these into a new helper for avoid duplication. Signed-off-by: Joao Martins Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Avihai Horon --- hw/vfio/common.c | 52 +++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 99acb998eb14..54b4a4fc7daf 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -933,23 +933,14 @@ static bool vfio_known_safe_misalignment(MemoryRegion= Section *section) return true; } =20 -static void vfio_listener_region_add(MemoryListener *listener, - MemoryRegionSection *section) +static bool vfio_listener_valid_section(MemoryRegionSection *section) { - VFIOContainer *container =3D container_of(listener, VFIOContainer, lis= tener); - hwaddr iova, end; - Int128 llend, llsize; - void *vaddr; - int ret; - VFIOHostDMAWindow *hostwin; - Error *err =3D NULL; - if (vfio_listener_skipped_section(section)) { trace_vfio_listener_region_add_skip( section->offset_within_address_space, section->offset_within_address_space + int128_get64(int128_sub(section->size, int128_one()))); - return; + return false; } =20 if (unlikely((section->offset_within_address_space & @@ -964,6 +955,24 @@ static void vfio_listener_region_add(MemoryListener *l= istener, section->offset_within_region, qemu_real_host_page_size()); } + return false; + } + + return true; +} + +static void vfio_listener_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOContainer *container =3D container_of(listener, VFIOContainer, lis= tener); + hwaddr iova, end; + Int128 llend, llsize; + void *vaddr; + int ret; + VFIOHostDMAWindow *hostwin; + Error *err =3D NULL; + + if (!vfio_listener_valid_section(section)) { return; } =20 @@ -1182,26 +1191,7 @@ static void vfio_listener_region_del(MemoryListener = *listener, int ret; bool try_unmap =3D true; =20 - if (vfio_listener_skipped_section(section)) { - trace_vfio_listener_region_del_skip( - section->offset_within_address_space, - section->offset_within_address_space + - int128_get64(int128_sub(section->size, int128_one()))); - return; - } - - if (unlikely((section->offset_within_address_space & - ~qemu_real_host_page_mask()) !=3D - (section->offset_within_region & ~qemu_real_host_page_mas= k()))) { - 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()); - } + if (!vfio_listener_valid_section(section)) { return; } =20 --=20 2.17.2