Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1534491imu; Tue, 11 Dec 2018 23:04:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/X3jX2vCQ/wJMZ16G1joY6KGT6W75Is5DYOFLf97Fxzw4enGPFJmZSyBm+00+5hEBMyH5I0 X-Received: by 2002:a17:902:8e8a:: with SMTP id bg10mr18955634plb.192.1544598265175; Tue, 11 Dec 2018 23:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544598265; cv=none; d=google.com; s=arc-20160816; b=0a/CAs/v5ULVIXjLPUmNy/Ex95SNkp8bSnjY20tcmMmOx19Whw1A7KFQlQYRLhMgkb 3gtVg7oei0o+ecSg/v+nbqZmNL73ZK3+EGH9M35rnFFbsixJcaBJjgwm3mYbsgXy92AU /7dK8YToIbL4fQ1nRY1vgQl5WMq2suizvN0QEAMm6wMFH1eQcapsJYIk/ug+i6n2/5HO YWZ6yD0x70FBpH1ClCbVzElaNchrKNqNtK3MYmQG+IBAvUzDfffHxubfsH90gSMlPhXq JxqSg7ryGJdkZrzWQvKkxzIspXAlFEKZnIlNpp+d+HtSVj6x3nArgBiPNQDcLpvNTw+k 5H2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=pNmrjLwI2DXlaRd7PguMnsmxYzkE+OpiDVSkcQ2K5e4=; b=j8PL+gLy3O33koQ/n9xUiY7wgjBLTB/TytsttNS2Uk4Uqhzfi0SNwoHh+H2Cg/LVTI odAAfMASHn+Ev8ermwsAEdovrDasqjsK3OUrEeatAEYeoSCCyZBM0ReXfqoQLKj6voAX ANX4fRCrLzjFcrR8Kwrff2tqq+kZFXK1Jv+VHxxHSUJI9aqJ3LzHTknnYEtgMU04ZfBU uQP0iqgoPkdD6vFw6r+IVnml4i+A71ZRUSh4Z9SZsdr0I28ZB4xJvsxQj1qdOCMX3cN3 32ZDe0Ld3LBog1u1yD/Zkn3xLVLBjK0NsMhTRULfyigR6Dgbvm/j3XKwfFAUykAjTuKK 7Trw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m38si13930706pgl.125.2018.12.11.23.04.04; Tue, 11 Dec 2018 23:04:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726490AbeLLHDQ (ORCPT + 99 others); Wed, 12 Dec 2018 02:03:16 -0500 Received: from mga14.intel.com ([192.55.52.115]:10182 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbeLLHDQ (ORCPT ); Wed, 12 Dec 2018 02:03:16 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 23:03:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="301463562" Received: from gao-cwp.sh.intel.com (HELO gao-cwp) ([10.239.159.28]) by fmsmga006.fm.intel.com with ESMTP; 11 Dec 2018 23:03:13 -0800 Date: Wed, 12 Dec 2018 15:06:56 +0800 From: Chao Gao To: Boris Ostrovsky Cc: Roger Pau =?iso-8859-1?Q?Monn=E9?= , linux-kernel@vger.kernel.org, Juergen Gross , Stefano Stabellini , Jia-Ju Bai , xen-devel@lists.xenproject.org, Jan Beulich Subject: Re: [PATCH] xen: xen-pciback: Reset MSI-X state when exposing a device Message-ID: <20181212070654.GA13411@gao-cwp> References: <1543976357-1053-1-git-send-email-chao.gao@intel.com> <20181205093223.dncg4nq4dh6xmrhk@mac> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 05, 2018 at 09:01:33AM -0500, Boris Ostrovsky wrote: >On 12/5/18 4:32 AM, Roger Pau Monn? wrote: >> On Wed, Dec 05, 2018 at 10:19:17AM +0800, Chao Gao wrote: >>> I find some pass-thru devices don't work any more across guest reboot. >>> Assigning it to another guest also meets the same issue. And the only >>> way to make it work again is un-binding and binding it to pciback. >>> Someone reported this issue one year ago [1]. More detail also can be >>> found in [2]. >>> >>> The root-cause is Xen's internal MSI-X state isn't reset properly >>> during reboot or re-assignment. In the above case, Xen set maskall bit >>> to mask all MSI interrupts after it detected a potential security >>> issue. Even after device reset, Xen didn't reset its internal maskall >>> bit. As a result, maskall bit would be set again in next write to >>> MSI-X message control register. >>> >>> Given that PHYSDEVOPS_prepare_msix() also triggers Xen resetting MSI-X >>> internal state of a device, we employ it to fix this issue rather than >>> introducing another dedicated sub-hypercall. >>> >>> Note that PHYSDEVOPS_release_msix() will fail if the mapping between >>> the device's msix and pirq has been created. This limitation prevents >>> us calling this function when detaching a device from a guest during >>> guest shutdown. Thus it is called right before calling >>> PHYSDEVOPS_prepare_msix(). >> s/PHYSDEVOPS/PHYSDEVOP/ (no final S). And then I would also drop the >> () at the end of the hypercall name since it's not a function. >> >> I'm also wondering why the release can't be done when the device is >> detached from the guest (or the guest has been shut down). This makes >> me worry about the raciness of the attach/detach procedure: if there's >> a state where pciback assumes the device has been detached from the >> guest, but there are still pirqs bound, an attempt to attach to >> another guest in such state will fail. > >I wonder whether this additional reset functionality could be done out >of xen_pcibk_xenbus_remove(). We first do a (best effort) device reset >and then do the extra things that are not properly done there. No. It cannot be done in xen_pcibk_xenbus_remove() without modifying the handler of PHYSDEVOP_release_msix. To do a successful Xen internal MSI-X state reset, PHYSDEVOP_{release, prepare}_msix should be finished without error. But ATM, xen expects that no msi is bound to pirq when doing PHYSDEVOP_release_msix. Otherwise it fails with error code -EBUSY. However, the expectation isn't guaranteed in xen_pcibk_xenbus_remove(). In some cases, if qemu fails to unmap MSIs, MSIs are unmapped by Xen at last minute, which happens after device reset in xen_pcibk_xenbus_remove(). Thanks Chao