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=-6.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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 1B2CFC433DF for ; Tue, 28 Jul 2020 09:00:09 +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 E0AC820775 for ; Tue, 28 Jul 2020 09:00:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0AC820775 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k0LSy-0001Yf-2t for qemu-devel@archiver.kernel.org; Tue, 28 Jul 2020 05:00:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0LSG-00017U-6n; Tue, 28 Jul 2020 04:59:24 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:57664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0LSD-0004pY-5F; Tue, 28 Jul 2020 04:59:23 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06S89IlU038839; Tue, 28 Jul 2020 04:59:18 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 32j213yaa4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jul 2020 04:59:17 -0400 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06S8A3WF040471; Tue, 28 Jul 2020 04:59:17 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 32j213ya8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jul 2020 04:59:17 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06S8pFok015516; Tue, 28 Jul 2020 08:59:14 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma05fra.de.ibm.com with ESMTP id 32gcqk1y6n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Jul 2020 08:59:14 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06S8vk0F66388256 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Jul 2020 08:57:46 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5C64AE051; Tue, 28 Jul 2020 08:59:11 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3A1F5AE059; Tue, 28 Jul 2020 08:59:11 +0000 (GMT) Received: from oc5500677777.ibm.com (unknown [9.145.68.234]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 28 Jul 2020 08:59:11 +0000 (GMT) Subject: Re: [RFC PATCH] s390x/pci: vfio-pci breakage with disabled mem enforcement To: Pierre Morel , Alex Williamson , Matthew Rosato References: <1595517236-17823-1-git-send-email-mjrosato@linux.ibm.com> <20200723102916.7cf15b43@w520.home> <0481c77e-f71f-886b-9b0a-41529eb139ee@linux.ibm.com> From: Niklas Schnelle Message-ID: Date: Tue, 28 Jul 2020 10:59:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <0481c77e-f71f-886b-9b0a-41529eb139ee@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-28_01:2020-07-27, 2020-07-28 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007280056 Received-SPF: pass client-ip=148.163.156.1; envelope-from=schnelle@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/28 04:59:18 X-ACL-Warn: Detected OS = Linux 3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, 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: david@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org, pasic@linux.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, rth@twiddle.net Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 7/27/20 5:40 PM, Pierre Morel wrote: > > > On 2020-07-23 18:29, Alex Williamson wrote: >> On Thu, 23 Jul 2020 11:13:55 -0400 >> Matthew Rosato wrote: >> >>> I noticed that after kernel commit abafbc55 'vfio-pci: Invalidate mmaps >>> and block MMIO access on disabled memory' vfio-pci via qemu on s390x >>> fails spectacularly, with errors in qemu like: >>> >>> qemu-system-s390x: vfio_region_read(0001:00:00.0:region0+0x0, 4) failed: Input/output error >>> >>>  From read to bar 0 originating out of hw/s390x/s390-pci-inst.c:zpci_read_bar(). >>> >>> So, I'm trying to figure out how to get vfio-pci happy again on s390x.  From >>> a bit of tracing, we seem to be triggering the new trap in >>> __vfio_pci_memory_enabled().  Sure enough, if I just force this function to >>> return 'true' as a test case, things work again. >>> The included patch attempts to enforce the setting, which restores everything >>> to working order but also triggers vfio_bar_restore() in the process....  So >>> this isn't the right answer, more of a proof-of-concept. >>> >>> @Alex: Any guidance on what needs to happen to make qemu-s390x happy with this >>> recent kernel change? >> >> Bummer!  I won't claim to understand s390 PCI, but if we have a VF >> exposed to the "host" (ie. the first level where vfio-pci is being >> used), but we can't tell that it's a VF, how do we know whether the >> memory bit in the command register is unimplemented because it's a VF >> or unimplemented because the device doesn't support MMIO?  How are the >> device ID, vendor ID, and BAR registers virtualized to the host?  Could >> the memory enable bit also be emulated by that virtualization, much >> like vfio-pci does for userspace?  If the other registers are >> virtualized, but these command register bits are left unimplemented, do >> we need code to deduce that we have a VF based on the existence of MMIO >> BARs, but lack of memory enable bit?  Thanks, >> >> Alex > > Alex, Matt, > > in s390 we have the possibility to assign a virtual function to a logical partition as function 0. > In this case it can not be treated as a virtual function but must be treated as a physical function. > This is currently working very well. Can you explain why it must be treated as a physical function and must not have is_virtfn set? I'm currently reworking my fix for PF/VF linking not happening for all ways to attach a VF and in that I intend to set is_virtfn = 1 also for VFs that are not linked with a PF including those attached to an LPAR. So far I really can not see a reason why that should not work since I was wrong before and Firmware does tell us that these are indeed VFs (zdev->is_physfn == 0). AFAIK on nearly all platforms guests will often have a VF as function zero on a bus because that is what I expect to happen if you pass it through as a PCI function. So unless I'm missing something, that just makes LPAR look more like a QEMU guest on another platform which is very likely much more well tested than treating a VF as a PF as we have been doing. > However, these functions do not set PCI_COMMAND_MEMORY as we need. > > Shouldn't we fix this inside the kernel, to keep older QMEU working? > > Then would it be OK to add a new bit/boolean inside the pci_dev/vfio_pci_device like, is_detached_vfn, that we could set during enumeration and test inside __vfio_pci_memory_enabled() to return true? This does not make sense to me, as I wrote above it's totally normal for VMs to see VFs detached from the PF as they are passed-through to a QEMU guest so IMHO that's already covered by the meaning of is_virtfn. > > In the enumeration we have the possibility to know if the function is a HW/Firmware virtual function on devfn 0 or if it is created by SRIOV. >