From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 9948D3B2D06 for ; Mon, 1 Jun 2026 13:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780321346; cv=none; b=OuDOXeeLBzvWBLbUamxjeA8CmrRt4FKl4Pt4F7qn5vtOw1keEydKqiTml7ShXARYNCLCFHeEGJnvW/prwsUSP7HXv+dRjnSnX8MirRjM0gdrOGiuXyt3zKoN+oBQbumtgI2SsD699csH1gNYLCe+WsVUyhz+J0FYXVuRiQEqCss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780321346; c=relaxed/simple; bh=w9aL2jXBkSQc60s7PCYdOXjxGsJtviB4VjNKmXS4Hw8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b3OBneg7XGRuACRApg6uIIv0PvIp2sfD4UUeZcLqaHxf1dI9ZZ2nKsLiTGnu92mcFUL/PteEVAZyVhvQyKvO1qGwTbCDSqedu4pAbEFnMOCA3WEEPyass8J8BeO1hlEUCr4LpCO6x+rm8ZKH1aqW2JxGHvNwopmxnjd8QVlAUBQ= 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=J5IpyRcY; arc=none smtp.client-ip=209.85.214.202 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="J5IpyRcY" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2bf11699875so45111255ad.1 for ; Mon, 01 Jun 2026 06:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780321345; x=1780926145; 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=pWexhegNnVMZtjViVug1/DougZixUK6pa8KgAqOhU80=; b=J5IpyRcYjT+9kfjvogEenlMSN5c8t00cMLIAfpYd2aYJrhhLO6/smbUfk9nHSOsGC/ /4mq4kxlTLH8YTg1MJHM4NglfYYEZSlOECnKAT9CuBBFze9uzgXTpZRdxQEem1NMWUXE BDTPPHaqIAUlQR9/w89tW8Fl0WozTuZmh9ozLPQgaFNUqLsMWFHFh1EJ/hPCQVMTlb9+ SnZpbuE/bt0ojSpitBPESCTFSPEJkHVAZYAv20+DXW3JeF+oeCJw8owJEOKvWWiBWt3z 6hL8g488Rh1D4Z/K+kb1l19KPjyHbIy4kETiNCZ8c2/M0XK2d2ji6+Bpt/caIApGGeO/ yysA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780321345; x=1780926145; 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=pWexhegNnVMZtjViVug1/DougZixUK6pa8KgAqOhU80=; b=NFoTzw6M3guCAYoqBI0R8JNbaYYyXXVtyxdL9twy34bP6Qag/OpWJ29CdOLtDuGKWz LIdsqdk0InRDLuR4UjSU7nNxMvALzCFfPvTSVbMVltq3GmSeCkQvYFOw33/1k/VbNxZa Exyh7nMZRHBIWeW0UoP9068eXkEPjNTs43M3j4wknZfkIrEXZx2RKgN0lZTNrSCoyawu ia7nSXVKXkGthEQS8F8nNMsVqXqmmosIwss3sFg08qv6fUq6OEhwIPOkCLLX1/M+JSIr IjcYXFpTL2eACub39KcIQpg/wTMO7H29lruXlSspLuSaCaHKqFAzw90fVPQj/Q9MhLW4 k1rQ== X-Forwarded-Encrypted: i=1; AFNElJ9wxnFb0+G6oDaRtWYv5ZK5xXIHnTvj/GJnOPedPi1NkeASjGpdzvwrsZBCUUvxhKOPckGJj8zSMNfKkQo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4IKNeiQXYxr3s+zK8BssAm8CUchqIXykn7SMcP4Unlx6WVcnN PxInrEw6Ka8WLMrzrfBsKriYIdfya+s4os3FpucfiMj3jmyTa/nMhRbLhEHI0phHS0lnS8ZZvUk 3SQ== X-Received: from plbke7.prod.google.com ([2002:a17:903:3407:b0:2bf:1274:55fb]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:cecc:b0:2c1:6ed:513b with SMTP id d9443c01a7336-2c106ed52bfmr2564075ad.16.1780321344530; Mon, 01 Jun 2026 06:42:24 -0700 (PDT) Date: Mon, 1 Jun 2026 13:42:04 +0000 In-Reply-To: <20260601134204.2150602-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: <20260601134204.2150602-1-praan@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260601134204.2150602-7-praan@google.com> Subject: [PATCH 6/6] PCI/ATS: Mandate checking pci_ats_supported() before pci_prepare_ats() From: Pranjal Shrivastava To: iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Joerg Roedel , Suravee Suthikulpanit , Vasant Hegde , Ankit Soni , Jason Gunthorpe , Bjorn Helgaas , Samiullah Khawaja , Pranjal Shrivastava , Baolu Lu , Nicolin Chen Content-Type: text/plain; charset="UTF-8" Currently, pci_prepare_ats() internally calls pci_ats_supported() and returns -EINVAL if the device does not support ATS. While this provides a silent safety check, it conflates support detection with configuration. Update pci_prepare_ats() to wrap the internal pci_ats_supported check in a WARN_ON(). This mandates all callers to call pci_prepare_ats() only if the function supports ATS. Update the function documentation to mention that callers must verify ATS support (via pci_ats_supported()) before calling pci_prepare_ats(). Suggested-by: Baolu Lu Reviewed-by: Nicolin Chen Signed-off-by: Pranjal Shrivastava --- drivers/pci/ats.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index ec6c8dbdc5e9..e10a0ceb2645 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -53,7 +53,9 @@ EXPORT_SYMBOL_GPL(pci_ats_supported); * @ps: the IOMMU page shift * * This must be done by the IOMMU driver on the PF before any VFs are created to - * ensure that the VF can have ATS enabled. + * ensure that the VF can have ATS enabled. Callers must verify that ATS is + * supported by the device (e.g. via pci_ats_supported()) before calling this + * function. * * Returns 0 on success, or negative on failure. */ @@ -61,7 +63,7 @@ int pci_prepare_ats(struct pci_dev *dev, int ps) { u16 ctrl; - if (!pci_ats_supported(dev)) + if (WARN_ON(!pci_ats_supported(dev))) return -EINVAL; if (WARN_ON(dev->ats_enabled)) -- 2.54.0.823.g6e5bcc1fc9-goog