From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (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 6F2DB3CAE75 for ; Fri, 29 May 2026 11:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780053140; cv=none; b=kDyjx4DzgFhIYp490zctcRLGMtQkRlcDq0ao/hrpPmou3fTzTSuLNrtanLuN5gmpCTvh1Rxz66HJuhSPAB0dEmM3Y4Maa8udDC/j0uZbVLreNAuCieeuAbYw8J3TBCqsvMM4BWd6Kzh2/mI0uij4d1S0X2drlVKaEGG8Ma+X8es= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780053140; c=relaxed/simple; bh=QMWF1Nn5UhAxAEgwX3QVOSlhArpqB7BokO3nvPMLRNI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u4ngmTVJOdAX8va5HvGFQ5pk4/2iCabBdQrM1/DNB6pkIe3T+xo9Kfv8Qj8vh/s4tfPEOpbW5dNnAVdhIwi1effQoxWGSDEEM2Ij2rYyGbmscsaX2/9MuSVQfMuQNGHi/HQvcMuWDmBB+bODvBTGyi3/oRuefZ2QtKEMJJYFYzM= 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=m1fE3xKg; arc=none smtp.client-ip=209.85.214.201 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="m1fE3xKg" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2babbeff9e4so154495755ad.0 for ; Fri, 29 May 2026 04:12:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780053137; x=1780657937; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V1OhefJlO7SddiDjet5+3aQQ9KCjHVV2cUEJthb1Tt4=; b=m1fE3xKgmoQxyQVYBM2Y242Rhp5O5KsxSpFv6Yp8D6kajc2VYFUl1a3VoI3W5V2M+z x54DvhQxn98JeczzUCnq534G5rCXm9h3+OaenubOBlNHnk3JnAhTuww2aSElGu86AKLl Jti0s7pgC/CGUULnL3ItTYMCjlQWDBNuhDELvTWiyAu4S94SMoAK4WPGDwdgVJQV2j2F Kq4aTTT4QJ1nC5gxHocytvClnYxmOGdV5VtkkhMut/M6StVSYBN+1HoDXZE3qrFYRtVX /cUwvPI65bzq9kDl9x27UrEc7dzYtx4JNtnAaE4uo54VL/WfuUZ5hscpuRrDrai1tQpd fggQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780053137; x=1780657937; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V1OhefJlO7SddiDjet5+3aQQ9KCjHVV2cUEJthb1Tt4=; b=b97E8KIBY/YDO44CVIT7WIY4nOz+cbFNUSKwt0DUZnnSe34r4VIVr5Op5kfGTy8haw O5N7Bb9rdQ82NW/va75ET7h+qV60Qm97HbGbu5s9u6mjyDyx4nHpA862AvzcyR3Ev2+g GXU5+ynE6al8Z6lEI62kQnUuMOqeg0JoktEQ/K/m8KRSVYeKjgtYBSMdjS9lcsQ1PMYI A0WNnla9GCkvGA3jsW5loh8hupPGn24rOz1lOrQsn5WGE0jWY4NJaQ8/WNcw0neSTJX4 vGRe/kYXt9osZyO/SqjjbQ+QMZSTcYfjA/d0lBwjcMeUWHZqY/CkcrdcNYEB3hFELQCE 67rQ== X-Forwarded-Encrypted: i=1; AFNElJ+IJNrgWgbj4781BMT8xPFaa/DVi/3kxLVM1CAd5RK/u+gq3BKmA+6CG9oGbnmxr8bC158syBO6Vz5iOrg=@vger.kernel.org X-Gm-Message-State: AOJu0YxvJ+a/vhFadKKOfX9QWQjrWEfuvw8Tz+Oz9M3zWIakxRhSzkQk 7bYMlAagm1+vzad1PWzmyE+XPAeBWlPbcBqjFug4BxvOeRMOG+mV8CmxktSQF8cajC/LUiYYQuh MFg== X-Received: from ploe7.prod.google.com ([2002:a17:903:2407:b0:2bf:a0d:a7e8]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:19cc:b0:2ba:838b:bfae with SMTP id d9443c01a7336-2bf20dfae24mr24843145ad.18.1780053136322; Fri, 29 May 2026 04:12:16 -0700 (PDT) Date: Fri, 29 May 2026 11:12:04 +0000 In-Reply-To: <20260529111208.387412-1-praan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260529111208.387412-1-praan@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260529111208.387412-3-praan@google.com> Subject: [PATCH v6 2/6] PCI/ATS: Validate STU for VFs in pci_prepare_ats() From: Pranjal Shrivastava To: iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Joerg Roedel , Will Deacon , Bjorn Helgaas , David Woodhouse , Lu Baolu , Robin Murphy , Suravee Suthikulpanit , Jason Gunthorpe , Nicolin Chen , David Matlack , Samiullah Khawaja , Daniel Mentz , Pasha Tatashin , Mostafa Saleh , Pranjal Shrivastava , Jason Gunthorpe Content-Type: text/plain; charset="UTF-8" While every PCI Function that implements ATS has an independent ATS Extended Capability structure with a Read/Write Smallest Translation Unit (STU) field, the kernel manages SR-IOV ATS by requiring the IOMMU driver to configure the STU on the Physical Function (PF) before any any Virtual Functions (VFs) are created. Currently, pci_prepare_ats() bails out early for VFs, assuming that the PF has already been correctly prepared. However, this creates a potential mismatch if a VF is subsequently prepared with a different page shift. Update pci_prepare_ats() to validate that the requested page shift (ps) matches the STU already configured in the associated PF. This ensures early detection of incompatible configurations and maintains the kernel's policy of consistent STU sizing across all functions associated with a given SMMU. Reviewed-by: Jason Gunthorpe Reviewed-by: Samiullah Khawaja Reviewed-by: Nicolin Chen Reviewed-by: Lu Baolu Signed-off-by: Pranjal Shrivastava --- drivers/pci/ats.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index 679a3c3c1d54..9cb23780093d 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -73,8 +73,12 @@ int pci_prepare_ats(struct pci_dev *dev, int ps) if (ps < PCI_ATS_MIN_STU) return -EINVAL; - if (dev->is_virtfn) + if (dev->is_virtfn) { + if (pci_physfn(dev)->ats_stu != ps) + return -EINVAL; + return 0; + } dev->ats_stu = ps; ctrl = PCI_ATS_CTRL_STU(dev->ats_stu - PCI_ATS_MIN_STU); -- 2.54.0.823.g6e5bcc1fc9-goog