From patchwork Tue Aug 22 10:56:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Shavit X-Patchwork-Id: 13360480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2BC43EE4993 for ; Tue, 22 Aug 2023 10:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZHv5JsYB4s4G4rG5DJqKRWfhLn1O61SoKMStXn1hSUc=; b=spnmy3KiyoXMn0SvjNpn31k82f A7F3Q66cjbNkoELKArc9scpvHYJ4fIEjYyOVfeumzSqnJzd0a0Jpi91VxX8J2kii2wsaay6EYhu8q cwZMt7feGysF1NxGvbkE0FGh0gKph993Z3gta2V9w8J6v6TlgDX02ksc2NuadLMi0LEpa6sQZ/tqd 8U6+faUmPZAZxmmDsCZ7Svw9XJSaikgH/kG4d7BimHAUhws48KzmjLLoGoFYjgDt9GtNdv8FRGZY+ G3yY/tjuAf/8sjXT3ENvEOEfi7E/aiP+Q+QQlpi4BWIs3WcoI7gIxqH7A1r0geZvKmFWXObdatFzv s8+isrxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYP5D-00FmIA-0z; Tue, 22 Aug 2023 10:57:59 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYP57-00FmFR-1N for linux-arm-kernel@lists.infradead.org; Tue, 22 Aug 2023 10:57:54 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-58d9e327d3aso61982377b3.3 for ; Tue, 22 Aug 2023 03:57:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1692701869; x=1693306669; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eMqZtDvlSX07gyZ0u5Dl6BMVcufM2gRGniU6L1WlEwU=; b=Ix94X6F96wzJuSjo8aNRndBwhpicfnsuKrnh/oKMivxMGel4dqf/ogPNg5Cjxvi5nr AB8AM/bRuJIrrA2LkbIZv5WEt0WUI8brlEapCeVt9GCvMcnD3igwxweGtHcPpHjgvUPP pv9/113iyGn0oOkSawXSC5qJDnIB64Zdyu1HfagqXJnoBMRljhv7MafWdZ08MfLITQzj 21J0HSfeNwlbaaDlfi6LLhjcmPouoCOnSrty8NKTE60KbB8hskmCwJ6xGsM/80vkjilK np0gAcI5YY62LjgdlEyDYVZw6pBStWJBQQYAVoUl0Io2mwf/zMAZy8YXueXOcT35V3v2 YuLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692701869; x=1693306669; 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=eMqZtDvlSX07gyZ0u5Dl6BMVcufM2gRGniU6L1WlEwU=; b=jd/Qc/jk3E3jXjaB9MQjO6rlaGnIBCkAj27PRysWp1ic1/GuAPOADfd+B9Vsx8AQ3F mFVg0Ma+PkUAk+wXkZuBVOQ5ZCePc9DZDRois7OHRBnGf4F9P45DHMHGmdXS04hcykH+ DLdvL6AZZrs56yX+0WWse58FjsRjKzYKL/wL+gOlLkdBcTO9mawDubv4LWJZujfb5pgi xljzSBHFJz4Nyo+qzJqCCKjoygnMzGiJMT9LPOHPnDBWD72ltVKjutSACLwlYtaLSWmq CzuUG6IVP8DOgXvdtMoG4T5QBciZf2JzykJascqlk8IjrRlzZ7PnUpHcYRQSHDJU1fOy dXiQ== X-Gm-Message-State: AOJu0Ywl4N8WslzjMdprVrYFe4OQVX58MZpg1i0uDOy09Dd6dlJNwxT6 001f795U6Tp1qQVjju0cD5nyANXRBerP X-Google-Smtp-Source: AGHT+IFl31R48qo4ur1dLKvDtJJz2U6vSie9HrG6LLwP12qhr8EwPDR8M4v6oArRwgOrfdiaqHOQuhpRrYQ8 X-Received: from mshavit.ntc.corp.google.com ([2401:fa00:95:20c:44ad:3968:8aaa:c4fe]) (user=mshavit job=sendgmr) by 2002:a0d:ec47:0:b0:579:e07c:2798 with SMTP id r7-20020a0dec47000000b00579e07c2798mr95478ywn.2.1692701869478; Tue, 22 Aug 2023 03:57:49 -0700 (PDT) Date: Tue, 22 Aug 2023 18:56:57 +0800 In-Reply-To: <20230822105738.1607365-1-mshavit@google.com> Mime-Version: 1.0 References: <20230822105738.1607365-1-mshavit@google.com> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog Message-ID: <20230822185632.RFC.v2.1.Ib87a2696f25414e0fc39cc22dc74e31a4415c2a1@changeid> Subject: [RFC PATCH v2 1/9] iommu/arm-smmu-v3: group attached devices by smmu From: Michael Shavit To: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: nicolinc@nvidia.com, tina.zhang@intel.com, jean-philippe@linaro.org, will@kernel.org, robin.murphy@arm.com, jgg@nvidia.com, Michael Shavit , Dawei Li , Jason Gunthorpe , Joerg Roedel , "Kirill A. Shutemov" , Lu Baolu , Mark Brown X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230822_035753_462371_57F09B1B X-CRM114-Status: GOOD ( 14.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Always insert a new master in the devices_list besides other masters that belong to the same smmu. This allows code to batch commands by SMMU when iterating over masters that a domain is attached to. Signed-off-by: Michael Shavit --- Changes in v2: - New commit drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index f17704c35858d..37b9223c145ba 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2382,6 +2382,24 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) arm_smmu_write_ctx_desc(master, 0, NULL); } +static void arm_smmu_domain_device_list_add(struct arm_smmu_domain *smmu_domain, + struct arm_smmu_master *master) +{ + struct arm_smmu_master *iter; + unsigned long flags; + + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + if (list_empty(&smmu_domain->devices)) + list_add(&master->domain_head, &smmu_domain->devices); + else { + list_for_each_entry(iter, &smmu_domain->devices, domain_head) + if (iter->smmu == master->smmu) + break; + list_add(&master->domain_head, &iter->domain_head); + } + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); +} + static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; @@ -2435,9 +2453,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS) master->ats_enabled = arm_smmu_ats_supported(master); - spin_lock_irqsave(&smmu_domain->devices_lock, flags); - list_add(&master->domain_head, &smmu_domain->devices); - spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + arm_smmu_domain_device_list_add(smmu_domain, master); if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { if (!master->cd_table.cdtab) {