From nobody Tue Nov 26 20:26:40 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1704711573; cv=none; d=zohomail.com; s=zohoarc; b=hJWOdPK4aKSaqLogK3ll/7eQ8skkpbiAyteW+ek0Do5uFyQsO9VLeJjMnBdX9Op3fCVQzNzjk/VeL+4doDi6mcYCgOGu9NYB6IpAS/4MCg4+RBQGPUx7twsAd24ciwpD0i/ebO3CedEsJhvtUJ0WODs9oF5Sp8Skj3H9JL4XaqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704711573; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tYYOOvHfhkgck3QqF8kym4SroXyG/FWDJsLrhrUthYw=; b=noS7kZR3qReNO44hCb25p9lX1YzDXfnumDNvR8QoxclA72V7jmgejLk4LUiiRCCJQruTiEFPXyVnIIGyvBJgujiERFV90C8QFeN0Gj0s/++WY8vSlB5XJPiGajyLws9a7oHHEYkx4X42e6iyB+Qvml1eIAqJSMNA/I3X5Z96BgA= 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 1704711573386514.3499530657091; Mon, 8 Jan 2024 02:59:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMnLZ-0004MJ-2m; Mon, 08 Jan 2024 05:59:09 -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 1rMnLX-0004MB-OF for qemu-devel@nongnu.org; Mon, 08 Jan 2024 05:59:07 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rMnLR-0006rX-FJ for qemu-devel@nongnu.org; Mon, 08 Jan 2024 05:59:07 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-336897b6bd6so1891597f8f.2 for ; Mon, 08 Jan 2024 02:59:00 -0800 (PST) Received: from Dev-shlomop.pliops.ent ([213.8.195.28]) by smtp.googlemail.com with ESMTPSA id f13-20020a05600c154d00b0040e3635ca65sm10651592wmg.2.2024.01.08.02.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 02:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704711538; x=1705316338; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tYYOOvHfhkgck3QqF8kym4SroXyG/FWDJsLrhrUthYw=; b=XtVbFKGk+pf9zn0/WrmsGK3cLxniDoIUwHsD5v/MvHbGJIbe0DpA3202hcubq4hdBH N9eIHhOFAEBL2bHnnoY/xjohpnRG3kN2O+vafCj3YbHFpMGQN6yWZs7OmpJS3RVipP0Y rkKgAKDEbE3EhU68fJdmXEvEkL43IdVN83RmuZwj70yuzxYq2Qj4DKQGwu15z9BtDeHI pHp4K7VRDHApObtlLGdS3HoSIR8qReGOvNmHQqmJvdbCs81vbo5ZT+Tu3O9M1SfGvHRt xq5XGT+e1BpjgT/TXjj/wYePr71QSq8o3AJOwNInevZsfhJb9aIRHpCrAI7uIqHZF8Wr K2+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704711538; x=1705316338; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tYYOOvHfhkgck3QqF8kym4SroXyG/FWDJsLrhrUthYw=; b=rxN6cfd3ElRPf/GQzoH+riiU2BEegfccKNFrHc+FyPMsKMofLZd+wJ9ZgoV1dmnswk p8oYhD7m++xgRHvtP8JaTQHP736UoQG9/wNe1voT8nqLBCGNvHYSYAteiqMz8jW8QNEg 9Ke+ojt6YbN9tfOz5caiWIEYKg1WLRNIt8ucxt7xoIGuEJj/EBg4UuThoovL7Wcq1V04 ov0DJH5963dpIJQKI8d5j+XP16Dn50b1CjLYLLzzbw84EjhTWywslE9zfSoX0zAFPc43 Dwh1a1DdR76xONMRbvnY8RtxdAl+ReNBjvUVC36IZXixTZHzAmaF2PbdHXfZE3ITHneK XiLw== X-Gm-Message-State: AOJu0YwQxCbCxG92HmWwUa8CUKpgD3gr3ewYgYXrWPaSGEXtYVQ0V/ju NLRXSsxV7UfWm10n5U9ft0bzemR2aXVPrA== X-Google-Smtp-Source: AGHT+IHdmlAZbvpVWVV8mt9t25my+50JXKk3WrFuKcwQrDo6JVHbgf2PCEGKIIcksQQr5QGd7sUZXw== X-Received: by 2002:a05:600c:190b:b0:40d:8ad9:b8f8 with SMTP id j11-20020a05600c190b00b0040d8ad9b8f8mr1550431wmq.10.1704711537794; Mon, 08 Jan 2024 02:58:57 -0800 (PST) From: Shlomo Pongratz X-Google-Original-From: Shlomo Pongratz To: qemu-devel@nongnu.org Cc: andrew.sminov@gmail.com, peter.maydell@linaro.com, shlomop@pliops.com, shlomopongratz@gmail.com Subject: [PATCH] Hanlde wrap around caused by the fact that perior to version 460A the limit was 32bit quantity. See Linux kernel code in: drivers/pci/controllers/dwc/pcie-designware.c function: __dw_pcie_prog_outbound_atu Now in a 64bit system the range can be above 4G but as long as the limit itself is less then 4G the overflow is avoided Date: Mon, 8 Jan 2024 12:57:27 +0200 Message-Id: <20240108105727.117431-1-shlomop@pliops.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a00:1450:4864:20::42b; envelope-from=shlomopongratz@gmail.com; helo=mail-wr1-x42b.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, FREEMAIL_FROM=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1704711573697100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Shlomo Pongratz --- hw/pci-host/designware.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/pci-host/designware.c b/hw/pci-host/designware.c index dd9e389c07..7ce4a6b64d 100644 --- a/hw/pci-host/designware.c +++ b/hw/pci-host/designware.c @@ -269,11 +269,24 @@ static void designware_pcie_update_viewport(Designwar= ePCIERoot *root, { const uint64_t target =3D viewport->target; const uint64_t base =3D viewport->base; - const uint64_t size =3D (uint64_t)viewport->limit - base + 1; const bool enabled =3D viewport->cr[1] & DESIGNWARE_PCIE_ATU_ENABLE; + uint64_t tbase, tlimit, size; =20 MemoryRegion *current, *other; =20 + /* + * Hanlde wrap around caused by the fact that perior to version 460A + * the limit was 32bit quantity. + * See Linux kernel code in: + * drivers/pci/controllers/dwc/pcie-designware.c + * function: __dw_pcie_prog_outbound_atu + * Now in a 64bit system the range can be above 4G but as long as + * the limit itself is less then 4G the overflow is avoided + */ + tbase =3D base & 0xffffffff; + tlimit =3D 0x100000000 + (uint64_t)viewport->limit; + size =3D ((tlimit - tbase) & 0xffffffff) + 1; + if (viewport->cr[0] =3D=3D DESIGNWARE_PCIE_ATU_TYPE_MEM) { current =3D &viewport->mem; other =3D &viewport->cfg; --=20 2.25.1