From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9EF142AF89 for ; Fri, 7 Aug 2026 20:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786133653; cv=none; b=JYvMvboRfZV0pITwadr2F8WqOhWTre95wW4dZKSiAfpRbPKr5UQojKt7qE0RQ5GEOdOzWKIbpBg//2AYsrNqs2BFXOmqjG8Aw4Uwnnyz5TawvBZITnOGwaAS6zBV79vJxcm10aYtrV1HH2QNMKFuHj/o4qr2ie80e2C/RAn78AY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786133653; c=relaxed/simple; bh=5rNp68+R40BGQmfkY3/WO4qJbrt+ow4vjgJ4ryV1oaY=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=pCFGaOm7n0W6Znk1N34pQ8j7kCHtVdmze1WbPYe8qoA3phnMdQtwj5QNhB7IxBoO9SDpVskNBfw0HtKBfgNobEuOjExUjIyk1Z2q83DvtjBVoVB4OXfYO1fyZfnjUBDK7+WP7GQOWb1f5StIX+WXimyq/eHy5FF8rtNbIvrbK3Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--praan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZPh/CcFV; arc=none smtp.client-ip=209.85.216.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--praan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZPh/CcFV" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38e5a616d07so3774979a91.2 for ; Fri, 07 Aug 2026 13:14:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786133651; x=1786738451; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=C/tZuAguZ+jLqZbm1tQw6HjSeO9yj89pOL8SmKdqQE4=; b=ZPh/CcFVtdjSBaLpyHMN5uxfcjyeQQWv5Eu2BiRlfPoxPYxrmIk/BQfULpHJ7dMCDc yjRJBEvN4QRKshY/2SUHx2ggyhAevzqacyVB0S6WRQQjKGaXJziKIVVlwHI3L+vJNVua f8R+rnZZcBXVTX5ngdgQgmJbq06jeugbQPVYpCVruOJBXMXWjPYbSUBYh3vnM64CJSsN LCcEJLnaNtUoUGAT9JiLfX5klSqaBK6leixjM0M0kGiVnZtAjGnhfd1qennuiHSN6Hg5 sbqKHHsT9jmD5JnchM7Qq4I35q/KQF6GVc2cvasC6luG4O8QhvgEhhCaN5plch+W4AuL 4gsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786133651; x=1786738451; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=C/tZuAguZ+jLqZbm1tQw6HjSeO9yj89pOL8SmKdqQE4=; b=oCG5xfKNjQ/02qM/Xh+yMVLlPguWB5KJgX+W8nQj9pumU2fwU0obkw+dIJdO8MroNM OGCAn9uPjBQ5b5EdxFYJWR39wqvQQUP81n2Xa1owEjOrK0wYJYvyylxTSmwrM42/OhL+ C2wdnbWNobv1JQsV0k7/G9CWNdWjZV6spD8adqqJmk6buF5dNT+I3tXFclYg46lg9XmD 2p89tHtH3t6/SY7nLRLb2bzCG5yV6leF57dfzzl+WytFYWo6lN4ZbxPK6drW20Gn08AR OhHTbM8wIFnLQnED0dIp0eEZj1oLPfLkLr4ErCAjJbjWtSuIMSxC+UacGIzrfUiX9nDZ 9fJg== X-Forwarded-Encrypted: i=1; AHgh+RrtQ9QLUkZZzAvm0s0L/w3acAz540HCQMUayyJEAnHv+XxWtLxVxTC0pHLYVlly4OfQ2KA/uAyIvuAP3I0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/05BwaV6Ul1SKHqeyJPWYtV0oOB1nN1LDcuDeVJ7E3ebi6cGi IqsX75zJk4blxGibGGw91y7Lbl8vPmBXEME1vQ7or0glKw2SkOYCHu26WZBg+sxwWTKj9jjoUH0 YdA== X-Received: from pjboj7.prod.google.com ([2002:a17:90b:4d87:b0:38e:a577:5cbd]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2548:b0:36b:77b9:5c8c with SMTP id 98e67ed59e1d1-39282428edbmr2346413a91.17.1786133650733; Fri, 07 Aug 2026 13:14:10 -0700 (PDT) Date: Fri, 7 Aug 2026 20:14:04 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260807201405.3717430-1-praan@google.com> Subject: [RFC PATCH v1 0/1] vfio/pci: Revoke BARs and DMABUFs during sysfs-triggered PCI reset From: Pranjal Shrivastava To: Alex Williamson , Kevin Tian , kvm@vger.kernel.org Cc: Jason Gunthorpe , Ankit Agrawal , Matt Evans , Leon Romanovsky , Vivek Kasireddy , Jacob Moroni , David Hu , Samiullah Khawaja , linux-kernel@vger.kernel.org, Pranjal Shrivastava Content-Type: text/plain; charset="UTF-8" Introduce PCI .reset_prepare and .reset_done handlers to safely revoke active userspace mappings and exported DMABUFs during sysfs-triggered device resets. We are seeing a situation where system health and monitoring daemons (at times erroneously) issue device resets via sysfs for devices bound to vfio-pci: echo 1 > /sys/bus/pci/devices/0000:01:00.0/reset However, because vfio-pci does not implement the .reset_prepare and .reset_done error handlers, this hardware reset occurs completely unnoticed by the VFIO driver. Consequently, active traditional userspace BAR mappings and exported DMABUFs are never zapped or revoked. Importers of the DMABUFs (e.g., RDMA drivers) continue to issue DMAs (such as PCIe Memory Writes) toward the Endpoint. These transactions are silently dropped by the root port or trigger CTOs while higher-level actions (e.g., RDMA reg_mr) continue to succeed. We'd like to fix this by implementing the PCI reset ops for vfio-pci that revoke the DMABUFs and zap the BARs while holding the memory lock allowing concurrent user accesses to sleep and fault back in once the reset completes. Note: I've tried to handle the locking as a first attempt here, there might've been some cases that were missed. Also, for the RFC, the drivers that implement their own pci_error_handlers (like nvgrace) are not altered for now. Quick Note about Matt's DMABUF mmap Series ========================================== While this patch is aimed for the current upstream code, I believe with Matt's refactor [1] these ops might change slightly. If we have consensus on this patch, I'd send another patch based to Matt based on their series for them to include it in their next version. [1] https://lore.kernel.org/all/20260715174737.15287-1-matt@ozlabs.org/ Thanks, Praan Pranjal Shrivastava (1): vfio/pci: Revoke BARs and DMABUFs during sysfs-triggered PCI reset drivers/vfio/pci/vfio_pci_core.c | 88 ++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 32 deletions(-) -- 2.55.0.679.g6767b8d81c-goog