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=-13.1 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,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 F378BC43464 for ; Sat, 19 Sep 2020 01:54:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C31B421481 for ; Sat, 19 Sep 2020 01:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726316AbgISByI (ORCPT ); Fri, 18 Sep 2020 21:54:08 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:51176 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726054AbgISByI (ORCPT ); Fri, 18 Sep 2020 21:54:08 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id EBEC54A831E356ED8E93; Sat, 19 Sep 2020 09:54:06 +0800 (CST) Received: from [10.174.185.226] (10.174.185.226) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Sat, 19 Sep 2020 09:54:00 +0800 Subject: Re: [PATCH 2/2] vfio/pci: Remove bardirty from vfio_pci_device To: Alex Williamson , Cornelia Huck CC: , , References: <20200917033128.872-1-yuzenghui@huawei.com> <20200917033128.872-2-yuzenghui@huawei.com> <20200917133537.17af2ef3.cohuck@redhat.com> <20200917160742.4e4d6efd@x1.home> From: Zenghui Yu Message-ID: <3b5214f9-9e17-2bcd-1b92-57bacc1c1b31@huawei.com> Date: Sat, 19 Sep 2020 09:54:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200917160742.4e4d6efd@x1.home> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.185.226] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alex, On 2020/9/18 6:07, Alex Williamson wrote: > On Thu, 17 Sep 2020 13:35:37 +0200 > Cornelia Huck wrote: > >> On Thu, 17 Sep 2020 11:31:28 +0800 >> Zenghui Yu wrote: >> >>> It isn't clear what purpose the @bardirty serves. It might be used to avoid >>> the unnecessary vfio_bar_fixup() invoking on a user-space BAR read, which >>> is not required when bardirty is unset. >>> >>> The variable was introduced in commit 89e1f7d4c66d ("vfio: Add PCI device >>> driver") but never actually used, so it shouldn't be that important. Remove >>> it. >>> >>> Signed-off-by: Zenghui Yu >>> --- >>> drivers/vfio/pci/vfio_pci_config.c | 7 ------- >>> drivers/vfio/pci/vfio_pci_private.h | 1 - >>> 2 files changed, 8 deletions(-) >> >> Yes, it seems to have been write-only all the time. > > I suspect the intent was that vfio_bar_fixup() could test > vdev->bardirty to avoid doing work if no BARs had been written since > they were last read. As it is now we regenerate vconfig for all the > BARs every time any offset of any of them are read. BARs aren't > re-read regularly and config space is not a performance path, Yes, it seems that Qemu itself emulates all BAR registers and will read the BAR from the kernel side only at initialization time. > but maybe > we should instead test if we see any regressions from returning without > doing any work in vfio_bar_fixup() if vdev->bardirty is false. Thanks, I will test it with the following diff. Please let me know which way do you prefer. diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index d98843feddce..77c419d536d0 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -515,7 +515,7 @@ static int vfio_basic_config_read(struct vfio_pci_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 *val) { - if (is_bar(offset)) /* pos == offset for basic config */ + if (is_bar(offset) && vdev->bardirty) /* pos == offset for basic config */ vfio_bar_fixup(vdev); count = vfio_default_config_read(vdev, pos, count, perm, offset, val); Thanks, Zenghui