Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1263499ybj; Thu, 7 May 2020 19:35:56 -0700 (PDT) X-Google-Smtp-Source: APiQypJPDiWSqUqNAoUDxacD65uXHNHO5ogWoeymAHnbmJfinvfz6s7XjnuY0d0Oqz+AWRV7eCTh X-Received: by 2002:a17:906:2b96:: with SMTP id m22mr86214ejg.330.1588905356695; Thu, 07 May 2020 19:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588905356; cv=none; d=google.com; s=arc-20160816; b=sFuvfIGpko683RSe3tXOCJlRCnyxU4YjCx7dBmO4dSbsk+zMiswPSxMtHgmydpQQI+ XDrjES/tAI9Sk4/2KdO4VXbhcdxZPG/yEsXkFXTMVDCUr4uPJyfFLeS/Q+6IeHiCCkms 2xVfuGQ80iRWUGFujqj38vcN8dwCftu17Br4GFji0G5q/xyOMJhFMScdwKebWskNboNB +MO42P93XIQlLB04znXxt90RYt6Hose90t6pl0gXv9T86/zuv3m5Qj+OXf4PhK1zSRtU fXRWGKPWXf7tG0MQsh9MVHg1kJAbHX7kOupjOVtCt+2Ph2BDdGkojYWdj7ZVkIvvQ9Xr Jj4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=bIUx96mA/EP7X7OGaqdPckgPL6bFvqgGtFSQHtpt5Dw=; b=wF0ki24F7qPWAZJdooYwkcAmDUAhyKsFJenYmw9Y0ZvTqiI/PJfmtxNS9IPSPZsEWy xmwJyVs4fnVi6jsA7WPO4sAiR5I6HorBSj2emzUTfXq9JnhDQ4SjEMG+SqlC5MCnln7Y cu9vfPfWJNkFURlndUceD98AIjywVE9JdLHfJY2UDx8/BnLugQ4O8P+CH7jYSYcuemjK pwtaor846e6y7tGje3/W1U2w9UaDkulu+Hy/s5vmVnjhcvNOK1fgJp4lY7cMacHOOmPH B2ybDM3qCXpn95eyolN/+uexDFwNvMTXVOmFgsyr6JF+9qg+FdYz813QW2Ljmp5GgO1q CWuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UHTHr65D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id aq1si148945ejc.344.2020.05.07.19.35.34; Thu, 07 May 2020 19:35:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UHTHr65D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726877AbgEHCcC (ORCPT + 99 others); Thu, 7 May 2020 22:32:02 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:42739 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726509AbgEHCcC (ORCPT ); Thu, 7 May 2020 22:32:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588905120; 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=bIUx96mA/EP7X7OGaqdPckgPL6bFvqgGtFSQHtpt5Dw=; b=UHTHr65DqkYo0WZzbShmHt4zB1NMRgUkslyHVcxls5WgfER/V2EJWgl9HmLdFkDxEZZcgi qFbA/nnim4M4dh3Tr1aScpVHZ0olLyw+j8gBNr3yPixIHGobQ7JVJ0AGmh8B13juCjG9cg WCHCjqX2lXmTbY+/+TWQY9Cm1KxhbXM= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-156-EqpMoSSFPMGcWHiYsTWV1A-1; Thu, 07 May 2020 22:31:59 -0400 X-MC-Unique: EqpMoSSFPMGcWHiYsTWV1A-1 Received: by mail-qt1-f199.google.com with SMTP id w12so146507qto.19 for ; Thu, 07 May 2020 19:31:58 -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=bIUx96mA/EP7X7OGaqdPckgPL6bFvqgGtFSQHtpt5Dw=; b=lG2R0jGeDotKmxmH7fYjR7Xotqb1SFH8zNaMRY2zKEPDS/OcLhqvfZjXF1X+3yL5Yf zXpwM7nGZPpFUMV+ZlapV+k1yPQhVH5IlzWHD2dQrNeCGqwoet3LiWAuDkZbNCUQcnxk CAsdEM0zggHT8drqsA4shtwDbJPhFvZNzNg/tPOnov1TqOIk5FvB/hYSlwPXmSYBOThX VnrBmicRfJiaRAWMdCW1fdjioY5JnH2Y+heMqdNIrwdc0iO5Pn20nyg64lHN7Znc/4k7 KNDqEykcTRR777F2obG4SaVksOXyryGUXxxUQXSoBE5CPNQxY2nO+aZ+J8gjfsud6JtO NRYg== X-Gm-Message-State: AGi0PubuJlenrC2OYDvYqWxLZQeLBwtVGpDedlF/xF8UeyXQfO1y9/j0 ib3F3fjBhL6vyv/3o8VucUaVDu1CX7H98Yt9dHn2aKPe9iu7tEiD7Fl5B565wBvaeVE2U5VmLvm kPiob60Ab4O30JM0HiYRE91Gt X-Received: by 2002:aed:2744:: with SMTP id n62mr612557qtd.112.1588905118349; Thu, 07 May 2020 19:31:58 -0700 (PDT) X-Received: by 2002:aed:2744:: with SMTP id n62mr612540qtd.112.1588905118097; Thu, 07 May 2020 19:31:58 -0700 (PDT) Received: from xz-x1 ([2607:9880:19c0:32::2]) by smtp.gmail.com with ESMTPSA id p22sm365463qte.2.2020.05.07.19.31.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 19:31:57 -0700 (PDT) Date: Thu, 7 May 2020 22:31:56 -0400 From: Peter Xu To: Alex Williamson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, cohuck@redhat.com, jgg@ziepe.ca Subject: Re: [PATCH v2 0/3] vfio-pci: Block user access to disabled device MMIO Message-ID: <20200508023156.GV228260@xz-x1> References: <158871401328.15589.17598154478222071285.stgit@gimli.home> <20200507215908.GQ228260@xz-x1> <20200507163437.77b4bf2e@x1.home> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200507163437.77b4bf2e@x1.home> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 07, 2020 at 04:34:37PM -0600, Alex Williamson wrote: > On Thu, 7 May 2020 17:59:08 -0400 > Peter Xu wrote: > > > On Tue, May 05, 2020 at 03:54:36PM -0600, Alex Williamson wrote: > > > v2: > > > > > > Locking in 3/ is substantially changed to avoid the retry scenario > > > within the fault handler, therefore a caller who does not allow retry > > > will no longer receive a SIGBUS on contention. IOMMU invalidations > > > are still not included here, I expect that will be a future follow-on > > > change as we're not fundamentally changing that issue in this series. > > > The 'add to vma list only on fault' behavior is also still included > > > here, per the discussion I think it's still a valid approach and has > > > some advantages, particularly in a VM scenario where we potentially > > > defer the mapping until the MMIO BAR is actually DMA mapped into the > > > VM address space (or the guest driver actually accesses the device > > > if that DMA mapping is eliminated at some point). Further discussion > > > and review appreciated. Thanks, > > > > Hi, Alex, > > > > I have a general question on the series. > > > > IIUC this series tries to protect illegal vfio userspace writes to device MMIO > > regions which may cause platform-level issues. That makes perfect sense to me. > > However what if the write comes from the devices' side? E.g.: > > > > - Device A maps MMIO region X > > > > - Device B do VFIO_IOMMU_DMA_MAP on Device A's MMIO region X > > (so X's MMIO PFNs are mapped in device B's IOMMU page table) > > > > - Device A clears PCI_COMMAND_MEMORY (reset, etc.) > > - this should zap all existing vmas that mapping region X, however device > > B's IOMMU page table is not aware of this? > > > > - Device B writes to MMIO region X of device A even if PCI_COMMAND_MEMORY > > cleared on device A's PCI_COMMAND register > > > > Could this happen? > > Yes, this can happen and Jason has brought up variations on this > scenario that are important to fix as well. I've got some ideas, but > the access in this series was the current priority. There are also > issues in the above scenario that if a platform considers a DMA write > to an invalid IOMMU PTE and triggering an IOMMU fault to have the same > severity as the write to disabled MMIO space we've prevented, then our > hands are tied. Thanks, I see the point now; it makes sense to start with a series like this. Thanks, Alex. -- Peter Xu