From patchwork Thu Apr 22 22:24:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 425880 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp764867jao; Thu, 22 Apr 2021 15:26:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCGCiyRTItaFzBAzDtdRMjWOs3+e2ovaZQ2vkWexP4Vi4f8TaAgC8jxR4L6QS7tDukkqfd X-Received: by 2002:a6b:720b:: with SMTP id n11mr1009526ioc.80.1619130366001; Thu, 22 Apr 2021 15:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619130365; cv=none; d=google.com; s=arc-20160816; b=aLAiQ0cQgZKfipPi6bKhj00cccetBJUxJ3RFZ7W08igiP+v0X+ZXN90eFYt559WVjC vsxI2LN72Otxd/YxuTThTI2yCsACk34j3RBG+hGCPP3foaQozhh1ksZ9oipQ+8K7dlJA W3cyhWsnGYkhRgMJSptOnFcr/OZbg/9G2Y5bm2zCrEZjNfNOsHcELiTWZQ9PwCcHojpj QP5A+ha6e7Bk16LZcfkKnnrXnzpc4suyBy392rwZXDPj6ttn7NaVcaoR1iCyH/+AgTFL kHRUkfoZUy/doVcIBx8N0vu5KXKN+q4ifckHQaLAwSHUn0JveN+0/SKwmhukQLjs81gB r1rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=919k9q2m+2zrPKFQ+Ec/Cc8wRWCIr42fDB+fDVUPS1k=; b=k5Gw4Dfy5wihaBJoNzqYLixgdFJ9oPqGTXf6/BM9D6hY0Pe13m9xTImdQc0YsBEmJQ Np1m1JT3l8K4mp76scTBtizkwbIDgYgRKutuvOI35RP+8DUa4YdCPIb5iPoh11hUsWmc 6VoidKtiD5PjlRXY5RglirBkEyNRsBxFBneW4TmKbgDYGIq1eSlrTWLv6m2vlfWfUcO6 vKSi5f9J7rfiarveh1wqY0IeAEjAlh9Pr/DJwIFEvr5zb8ixsfrDEOup5r6l4Zy++goa 3lAep+fSoKKTjUreET8KYCeSnakK7QPtlcVgQN1fKnR1zWjEgCPsdIN0elrHVfh+WjT4 wMBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=AK6IVIz3; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q3si4293109ios.60.2021.04.22.15.26.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Apr 2021 15:26:05 -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=fail header.i=@redhat.com header.s=mimecast20190719 header.b=AK6IVIz3; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:34696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZhlt-0003R3-Ey for patch@linaro.org; Thu, 22 Apr 2021 18:26:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZhkt-0003Q9-KO for qemu-devel@nongnu.org; Thu, 22 Apr 2021 18:25:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZhkp-0003Mf-3Y for qemu-devel@nongnu.org; Thu, 22 Apr 2021 18:25:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619130297; 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: in-reply-to:in-reply-to:references:references; bh=919k9q2m+2zrPKFQ+Ec/Cc8wRWCIr42fDB+fDVUPS1k=; b=AK6IVIz3cg5kJjP3te0pYdhMQHO+jvTczqMgiIWq+nVl3x/o3w4tdoV+Ue+LVbz+k+8bDd RoFQHFsjfc9ifcFuDrehkysYsSS4dlP473U+B1lKpOmS1x+4qrrJB71Bm/1/8S2kxgc+ub 2q7DFQtU+3YVWYnZT6xDoCjZre/RA7g= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-522-N_ldELDIM-KfjTjkqIZcVA-1; Thu, 22 Apr 2021 18:24:55 -0400 X-MC-Unique: N_ldELDIM-KfjTjkqIZcVA-1 Received: by mail-ed1-f72.google.com with SMTP id d2-20020aa7d6820000b0290384ee872881so13419949edr.10 for ; Thu, 22 Apr 2021 15:24:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=919k9q2m+2zrPKFQ+Ec/Cc8wRWCIr42fDB+fDVUPS1k=; b=rfa5tdAQpyNuar0yNnvNTj5aSG6pdLkZvgwrAMXf9f1VxCCTLvEVZujZrXfpYL1M++ 2vdazKklLC7F5pMkDRq90cR8dxStimXGhLlXrFa7rIUTi99B0Iq4Nzv67cGV1kutP8j+ br9nN5a1gra4y044/vnHghgphIBFG7xpmH2EGz1LKKxyQUiz5igVBMPFsSaJqPhqUSEO v7sIQ9H+oWqryhil4/Td1eNKy6gOHdyYT9tk5wqexrReVICs+9ERhGEP/p417eUy6qXP 8sIkdc9E73ruHITMCdV1c/H7U/262O9GVTx4Xsu4mqHvjVIQG8YSnKaol6zQ/caNUarK ZIkA== X-Gm-Message-State: AOAM530t4iDAWRTWpXpTZ45VhhXnSoYWjQ6N7g4vWQn+4C+KR6u/B7q/ g2nsveLiRVwxkSrzwnXYueRCm3erPodW+puzZnaCvwYXvW3BpFX5QxFgNxxhYoJz8WLaL8nJeyH QyLvBdFJH5JfY9vU7ZGN+Xa+QMXIDtY3hQs9SfnX4G5i/gJiJyAPxSpTcEvq2 X-Received: by 2002:aa7:d9d7:: with SMTP id v23mr762077eds.281.1619130294339; Thu, 22 Apr 2021 15:24:54 -0700 (PDT) X-Received: by 2002:aa7:d9d7:: with SMTP id v23mr762038eds.281.1619130294020; Thu, 22 Apr 2021 15:24:54 -0700 (PDT) Received: from redhat.com (212.116.168.114.static.012.net.il. [212.116.168.114]) by smtp.gmail.com with ESMTPSA id t17sm3251124edv.3.2021.04.22.15.24.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 15:24:53 -0700 (PDT) Date: Thu, 22 Apr 2021 18:24:51 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 1/2] amd_iommu: Fix pte_override_page_mask() Message-ID: <20210422222429.183108-2-mst@redhat.com> References: <20210422222429.183108-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20210422222429.183108-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.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_HIGH=-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_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Eduardo Habkost , Jean-Philippe Brucker , Richard Henderson , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Jean-Philippe Brucker AMD IOMMU PTEs have a special mode allowing to specify an arbitrary page size. Quoting the AMD IOMMU specification: "When the Next Level bits [of a pte] are 7h, the size of the page is determined by the first zero bit in the page address, starting from bit 12." So if the lowest bits of the page address is 0, the page is 8kB. If the lowest bits are 011, the page is 32kB. Currently pte_override_page_mask() doesn't compute the right value for this page size and amdvi_translate() can return the wrong guest-physical address. With a Linux guest, DMA from SATA devices accesses the wrong memory and causes probe failure: qemu-system-x86_64 ... -device amd-iommu -drive id=hd1,file=foo.bin,if=none \ -device ahci,id=ahci -device ide-hd,drive=hd1,bus=ahci.0 [ 6.613093] ata1.00: qc timeout (cmd 0xec) [ 6.615062] ata1.00: failed to IDENTIFY (I/O error, err_mask=0x4) Fix the page mask. Signed-off-by: Jean-Philippe Brucker Message-Id: <20210421084007.1190546-1-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/i386/amd_iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- MST diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 74a93a5d93..43b6e9bf51 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -860,8 +860,8 @@ static inline uint8_t get_pte_translation_mode(uint64_t pte) static inline uint64_t pte_override_page_mask(uint64_t pte) { - uint8_t page_mask = 12; - uint64_t addr = (pte & AMDVI_DEV_PT_ROOT_MASK) ^ AMDVI_DEV_PT_ROOT_MASK; + uint8_t page_mask = 13; + uint64_t addr = (pte & AMDVI_DEV_PT_ROOT_MASK) >> 12; /* find the first zero bit */ while (addr & 1) { page_mask++;