From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4335BC433ED for ; Wed, 7 Apr 2021 08:26:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C81AC6139E for ; Wed, 7 Apr 2021 08:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C81AC6139E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lU3Vt-00034r-RJ for qemu-devel@archiver.kernel.org; Wed, 07 Apr 2021 04:26:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lU3Uj-0002A0-M8 for qemu-devel@nongnu.org; Wed, 07 Apr 2021 04:25:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lU3Uh-0001c1-O0 for qemu-devel@nongnu.org; Wed, 07 Apr 2021 04:25:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617783898; 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=6ZcQgw5XguEHmXoXGID1KIq7ajQ474IJffTEJwyERVg=; b=IL01BOJ7YG0wTCGPumUC2H8Yx76ZFLh3eo2jvNUBqthgmLOtn5Wdey272M3Ys9zN7CamD3 R4LkMaYwGwZA4LzlPNQVZVTBe9FlvjCnTWPp3eEpH+ACWGBkV9ItdIp5PoKwr4tIxljcLQ l+GE7dhJCByuFtf1qekfEJunz6JJVSI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-xPGJ8kD4NGOmYonvUscnSw-1; Wed, 07 Apr 2021 04:24:57 -0400 X-MC-Unique: xPGJ8kD4NGOmYonvUscnSw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4950783DD24; Wed, 7 Apr 2021 08:24:56 +0000 (UTC) Received: from wangxiaodeMacBook-Air.local (ovpn-13-236.pek2.redhat.com [10.72.13.236]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D88A1000358; Wed, 7 Apr 2021 08:24:47 +0000 (UTC) Subject: Re: [PATCH V2] virtio-pci: compat page aligned ATS To: "Dr. David Alan Gilbert" References: <20210406040330.11306-1-jasowang@redhat.com> From: Jason Wang Message-ID: <3537aa98-f6fc-bf99-cbc6-3c90f1387dc5@redhat.com> Date: Wed, 7 Apr 2021 16:24:45 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jasowang@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=216.205.24.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 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, MIME_CHARSET_FARAWAY=2.45, NICE_REPLY_A=-0.001, 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=unavailable 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: qemu-devel@nongnu.org, qemu-stable@nongnu.org, ehabkost@redhat.com, peterx@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" ÔÚ 2021/4/6 ÏÂÎç5:39, Dr. David Alan Gilbert дµÀ: > * Jason Wang (jasowang@redhat.com) wrote: >> Commit 4c70875372b8 ("pci: advertise a page aligned ATS") advertises >> the page aligned via ATS capability (RO) to unbrek recent Linux IOMMU >> drivers since 5.2. But it forgot the compat the capability which >> breaks the migration from old machine type: >> >> (qemu) qemu-kvm: get_pci_config_device: Bad config data: i=0x104 read: >> 0 device: 20 cmask: ff wmask: 0 w1cmask:0 >> >> This patch introduces a new parameter "x-ats-page-aligned" for >> virtio-pci device and turns it on for machine type which is newer than >> 5.1. > I don't know the IOMMU code, but from the property/hw_compat I think > this is OK. > It's a bit tricky; since this was broken in 5.2, changing the > hw_compat_5_1 means that there are exisitng 5.2 users who will be broken > - howeer, the original 4c70875372b8 patch was sent to qemu-stable > which I think means there are other versions that are inconsistent as > well. Good point. It's not an easy task, we need to choose to break migration or virtio with vIOMMU. This patch chooes to do the latter, or is there any other better way to solve this? Thanks > > Dave > >> Cc: Michael S. Tsirkin >> Cc: Peter Xu >> Cc: Dr. David Alan Gilbert >> Cc: qemu-stable@nongnu.org >> Fixes: 4c70875372b8 ("pci: advertise a page aligned ATS") >> Signed-off-by: Jason Wang >> --- >> Changes since V1: >> - switch to use "x-ats-page-aligned" instead >> --- >> hw/core/machine.c | 1 + >> hw/pci/pcie.c | 10 ++++++---- >> hw/virtio/virtio-pci.c | 5 ++++- >> hw/virtio/virtio-pci.h | 5 +++++ >> include/hw/pci/pcie.h | 2 +- >> 5 files changed, 17 insertions(+), 6 deletions(-) >> >> diff --git a/hw/core/machine.c b/hw/core/machine.c >> index 9935c6ddd5..a50f2d5f0a 100644 >> --- a/hw/core/machine.c >> +++ b/hw/core/machine.c >> @@ -53,6 +53,7 @@ GlobalProperty hw_compat_5_1[] = { >> { "nvme", "use-intel-id", "on"}, >> { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */ >> { "pl011", "migrate-clk", "off" }, >> + { "virtio-pci", "x-ats-page-aligned", "off"}, >> }; >> const size_t hw_compat_5_1_len = G_N_ELEMENTS(hw_compat_5_1); >> >> diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c >> index a733e2fb87..fd0fa157e8 100644 >> --- a/hw/pci/pcie.c >> +++ b/hw/pci/pcie.c >> @@ -963,16 +963,18 @@ void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num) >> pci_set_quad(dev->config + offset + pci_dsn_cap, ser_num); >> } >> >> -void pcie_ats_init(PCIDevice *dev, uint16_t offset) >> +void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned) >> { >> pcie_add_capability(dev, PCI_EXT_CAP_ID_ATS, 0x1, >> offset, PCI_EXT_CAP_ATS_SIZEOF); >> >> dev->exp.ats_cap = offset; >> >> - /* Invalidate Queue Depth 0, Page Aligned Request 1 */ >> - pci_set_word(dev->config + offset + PCI_ATS_CAP, >> - PCI_ATS_CAP_PAGE_ALIGNED); >> + /* Invalidate Queue Depth 0 */ >> + if (aligned) { >> + pci_set_word(dev->config + offset + PCI_ATS_CAP, >> + PCI_ATS_CAP_PAGE_ALIGNED); >> + } >> /* STU 0, Disabled by default */ >> pci_set_word(dev->config + offset + PCI_ATS_CTRL, 0); >> >> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c >> index 883045a223..2b7142a21e 100644 >> --- a/hw/virtio/virtio-pci.c >> +++ b/hw/virtio/virtio-pci.c >> @@ -1848,7 +1848,8 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) >> } >> >> if (proxy->flags & VIRTIO_PCI_FLAG_ATS) { >> - pcie_ats_init(pci_dev, last_pcie_cap_offset); >> + pcie_ats_init(pci_dev, last_pcie_cap_offset, >> + proxy->flags & VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED); >> last_pcie_cap_offset += PCI_EXT_CAP_ATS_SIZEOF; >> } >> >> @@ -1925,6 +1926,8 @@ static Property virtio_pci_properties[] = { >> ignore_backend_features, false), >> DEFINE_PROP_BIT("ats", VirtIOPCIProxy, flags, >> VIRTIO_PCI_FLAG_ATS_BIT, false), >> + DEFINE_PROP_BIT("x-ats-page-aligned", VirtIOPCIProxy, flags, >> + VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT, true), >> DEFINE_PROP_BIT("x-pcie-deverr-init", VirtIOPCIProxy, flags, >> VIRTIO_PCI_FLAG_INIT_DEVERR_BIT, true), >> DEFINE_PROP_BIT("x-pcie-lnkctl-init", VirtIOPCIProxy, flags, >> diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h >> index d7d5d403a9..2446dcd9ae 100644 >> --- a/hw/virtio/virtio-pci.h >> +++ b/hw/virtio/virtio-pci.h >> @@ -42,6 +42,7 @@ enum { >> VIRTIO_PCI_FLAG_INIT_PM_BIT, >> VIRTIO_PCI_FLAG_INIT_FLR_BIT, >> VIRTIO_PCI_FLAG_AER_BIT, >> + VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT, >> }; >> >> /* Need to activate work-arounds for buggy guests at vmstate load. */ >> @@ -84,6 +85,10 @@ enum { >> /* Advanced Error Reporting capability */ >> #define VIRTIO_PCI_FLAG_AER (1 << VIRTIO_PCI_FLAG_AER_BIT) >> >> +/* Page Aligned Address space Translation Service */ >> +#define VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED \ >> + (1 << VIRTIO_PCI_FLAG_ATS_PAGE_ALIGNED_BIT) >> + >> typedef struct { >> MSIMessage msg; >> int virq; >> diff --git a/include/hw/pci/pcie.h b/include/hw/pci/pcie.h >> index 14c58ebdb6..6063bee0ec 100644 >> --- a/include/hw/pci/pcie.h >> +++ b/include/hw/pci/pcie.h >> @@ -137,7 +137,7 @@ void pcie_acs_reset(PCIDevice *dev); >> >> void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn); >> void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num); >> -void pcie_ats_init(PCIDevice *dev, uint16_t offset); >> +void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned); >> >> void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, >> Error **errp); >> -- >> 2.24.3 (Apple Git-128) >>