From patchwork Fri Jul 7 15:17:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 700035 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp3929498wrs; Fri, 7 Jul 2023 08:19:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlEuT0bCJJWPfdiWAFErCqKF1Eqmv/eBMhKzFUys8Gp5SQ+9wygBKwsok5gX1BAN58NIk0Yu X-Received: by 2002:a81:83c2:0:b0:579:dd41:468e with SMTP id t185-20020a8183c2000000b00579dd41468emr5419900ywf.22.1688743151267; Fri, 07 Jul 2023 08:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688743151; cv=none; d=google.com; s=arc-20160816; b=UzeCoiwyEl8G7kBDwaHA1aqJy258D9hEHssYvWR+CpLtayQ1TAogwEURiEXHkXKTaj OFaNpNrdlkLLnCl03vJjEzHPGMSwqxoQMmWERO9XHGm71oYWYni8QAhejsq7J/fO/IRz Ngbd3uBVIIbPuW1CR8gP64L3Hu7lMW4IHmvOcig5Fmpmgd8b+/IxjP3M8koWUAX4eJo1 OHbSSlYUwgwZQuT+yckp1DCPeZj6BxM4JMUzzkW161pBxVfKlquS7EWzBnNUPyUbsCad vqQKzrFEcnFUKy6+1zbFEjIDuGJV2d/xHApnODRb3v/EajnBOKBkOfx/yPBGH2OxnvHw Eanw== 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=aWI/6gGfjRPtDVKiMDrKPzVxOvluZG91V1TrcTp6oHQ=; fh=aRxBrgA7CrSouwdXoZUw1AmyeDG9xQchBaflhNgNTHQ=; b=Lr2dJEjWU6db7NIYLxE+cqCdSdFHoP4rrwBWObC/fvoHYUI8SjAVeHxuK+wNsjg/PZ Qs2xGW7MUUSv8ONcXe3jRXVwVV1Olm76MaRUN4Mr8juSJJKqxC/12g0eyDda8ZxHKsA9 q+KR+cMhvk1EmddHKP4zJW5g4BCWKPpom3Zaz2QCoqCHiUqEJXOBK5uMuyDO8LYbf0Tz QoFGiXKEcOnmJr2fCEXPjGI3qJaU2MbHaY3lpB4ErapbZDlumv3fJIeu5vNqBjNMYhWU f4opjKIwIzCdqGHEH6PleqpH65T+dJ5hPQbVmFngIi0y7mfX2yU0Zu/dK8DJcGdO+pXV B6/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NyeQ4dMR; 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 s20-20020a05622a019400b003f8b05ee732si2628675qtw.375.2023.07.07.08.19.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jul 2023 08:19:11 -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=NyeQ4dMR; 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 1qHnDZ-00013z-CA; Fri, 07 Jul 2023 11:17:57 -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 1qHnDY-00013q-OP for qemu-devel@nongnu.org; Fri, 07 Jul 2023 11:17:56 -0400 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qHnDX-0000h7-3i for qemu-devel@nongnu.org; Fri, 07 Jul 2023 11:17:56 -0400 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f76a0a19d4so3097962e87.2 for ; Fri, 07 Jul 2023 08:17:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688743073; x=1691335073; 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=aWI/6gGfjRPtDVKiMDrKPzVxOvluZG91V1TrcTp6oHQ=; b=NyeQ4dMRbWn/YUkvk1FsWkyAaQkj1jIJpKpJevZmg0hz8vbFHxr03fLrP//b24TBtJ 2XvpeGk2KTosfWJYHsNWsFYFmiNHBnYRPgQLPFEo1Yxa6rBWxl3tNWHld0xe7JZbI0Vh vjWMMhvMvw9u+ecUTaq6NFSh6O2OcGQbx8dU+oixf2xEbYddfjglAHxUGfY5neE/mtGB oIRxsZoj3DxgVPhxMskREaKJx+8mM5cVki54nKtSVrw1GVr40nWENC7lyCjgnFLEqdmA IobAwcpoN7u+lT/bhlqMgrllUOhFvvc1tquRvhX/vd4m4O/5Ij6QGH/rAdSWWIDu9eaQ cBhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688743073; x=1691335073; 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=aWI/6gGfjRPtDVKiMDrKPzVxOvluZG91V1TrcTp6oHQ=; b=V3SN0SUisja6Bz2mDzQa1yGG+sU8cFaSnuhkVsiL7mZLbwoZaHh5w1CJfDqVtWUrOd JuRWAr2nJHmWILQGPZ8JQNNHN0vNSmUkNzNychb/pgI0Ygq/ZlHC9U8As4Opig4AXMWG whM37mqH16XgmA3kbKHuKiAgdjGJAx649vrozSvFEoqPPgS5vIoWR/bh/eRnJVxJDnXj ZJah8CZV/yhfLaO7e++Y62xgmMLZB+Bg43bZGrYP0vpXjoCWGlSraj6TwzGGaKsJdvC9 2ed9ZrfKlSLyPyyrZfep5NoUGbxVry9ZAoPdgSgEXhh/58MjtJtN18ByQIRVymkCITaL uCRw== X-Gm-Message-State: ABy/qLZQFLXJ0dzZqxxeFspU+umlBb4YWq6wEF83JthuHoQ67+WVDyE4 qDChQM+q/N2P06v3vVB5Aez5G1xVJEk2E+528/Y= X-Received: by 2002:a05:6512:33ce:b0:4f8:5600:9e5e with SMTP id d14-20020a05651233ce00b004f856009e5emr4878565lfg.47.1688743073156; Fri, 07 Jul 2023 08:17:53 -0700 (PDT) Received: from m1x-phil.lan ([176.187.215.192]) by smtp.gmail.com with ESMTPSA id v2-20020a5d6102000000b003144bfbd0b3sm4695435wrt.37.2023.07.07.08.17.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 07 Jul 2023 08:17:52 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Thomas Huth , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 4/6] hw/virtio/vhost-vdpa: Use target-agnostic qemu_target_page_mask() Date: Fri, 7 Jul 2023 17:17:17 +0200 Message-Id: <20230707151719.70613-5-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230707151719.70613-1-philmd@linaro.org> References: <20230707151719.70613-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::135; envelope-from=philmd@linaro.org; helo=mail-lf1-x135.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, 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Similarly to commit e414ed2c47 ("virtio-iommu: Use target-agnostic qemu_target_page_mask"), Replace the target-specific TARGET_PAGE_SIZE and TARGET_PAGE_MASK definitions by a call to the runtime qemu_target_page_size() helper which is target agnostic. Signed-off-by: Philippe Mathieu-Daudé --- hw/virtio/vhost-vdpa.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index a3dd7c712a..456a0afe2e 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -14,6 +14,7 @@ #include #include #include +#include "exec/target_page.h" #include "hw/virtio/vhost.h" #include "hw/virtio/vhost-backend.h" #include "hw/virtio/virtio-net.h" @@ -23,7 +24,6 @@ #include "migration/blocker.h" #include "qemu/cutils.h" #include "qemu/main-loop.h" -#include "cpu.h" #include "trace.h" #include "qapi/error.h" @@ -313,9 +313,11 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, Int128 llend, llsize; void *vaddr; int ret; + int page_size = qemu_target_page_size(); + int page_mask = page_size - 1; if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, - v->iova_range.last, TARGET_PAGE_MASK)) { + v->iova_range.last, page_mask)) { return; } if (memory_region_is_iommu(section->mr)) { @@ -323,14 +325,14 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, return; } - if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != - (section->offset_within_region & ~TARGET_PAGE_MASK))) { + if (unlikely((section->offset_within_address_space & ~page_mask) != + (section->offset_within_region & ~page_mask))) { error_report("%s received unaligned region", __func__); return; } - iova = ROUND_UP(section->offset_within_address_space, TARGET_PAGE_SIZE); - llend = vhost_vdpa_section_end(section, TARGET_PAGE_MASK); + iova = ROUND_UP(section->offset_within_address_space, page_size); + llend = vhost_vdpa_section_end(section, page_mask); if (int128_ge(int128_make64(iova), llend)) { return; } @@ -396,23 +398,25 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, hwaddr iova; Int128 llend, llsize; int ret; + int page_size = qemu_target_page_size(); + int page_mask = page_size - 1; if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, - v->iova_range.last, TARGET_PAGE_MASK)) { + v->iova_range.last, page_mask)) { return; } if (memory_region_is_iommu(section->mr)) { vhost_vdpa_iommu_region_del(listener, section); } - if (unlikely((section->offset_within_address_space & ~TARGET_PAGE_MASK) != - (section->offset_within_region & ~TARGET_PAGE_MASK))) { + if (unlikely((section->offset_within_address_space & ~page_mask) != + (section->offset_within_region & ~page_mask))) { error_report("%s received unaligned region", __func__); return; } - iova = ROUND_UP(section->offset_within_address_space, TARGET_PAGE_SIZE); - llend = vhost_vdpa_section_end(section, TARGET_PAGE_MASK); + iova = ROUND_UP(section->offset_within_address_space, page_size); + llend = vhost_vdpa_section_end(section, page_mask); trace_vhost_vdpa_listener_region_del(v, iova, int128_get64(int128_sub(llend, int128_one())));