From patchwork Thu Jun 20 17:56:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13706202 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 D42ABC2BA1A for ; Thu, 20 Jun 2024 17:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=FVRB/LnGLBQUnkE/Rs06iVVHTa ZtfE46urZ9xlH2rBZW9AQtmGME/VUXZxM2ZUtLViIMGks8Z4DYTVY9ICyTK6OvorxNZTdjJy0v7bp k7WQRjALhwQ+dbj5PKkhh8kBWdH4AkCPJ/SqY81VlUF9e5B+AIiWXRGX2sZPr1fjNdwNx9b4h8z3l Mz9OKJWHu6EXDAByPr5F56HXd51Gb5SmCFOo6ZCvKw1keEGFe5gi9XT42cpjhSOqxaGuV95NmlVgB ECveBFtCBhgDtNoqwqh3YR2S/6RZ1zFbB5JZ8RDtZP0ntQWB0nyF0TbkBEtF+k+KNIfo6VaruGBns XrrLn0gA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM3j-00000006BCG-2M8t; Thu, 20 Jun 2024 17:58:55 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sKM2u-00000006Ahv-1scc for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2024 17:58:11 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-701b0b0be38so1100097b3a.0 for ; Thu, 20 Jun 2024 10:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718906283; x=1719511083; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=mHIgfF0EzJ2IsoSU2xVh/5fhHDS2ZoNuJFLckDd1BoRbXJZx1vDC2qEE253wH/CwvG SUE1O+c3TBbuXJTQUIbllYgvyCZBmEHjCOZccETBY+L5NrYvXPxXKagxQGhbfChXvY2H Awfu4tsr18/e91fbsx2ssd2MQ+OkTwUUnNwKKWQgGB2Jsr+oUQ4kxn4RUqNcKmpTtY+z 7cEGChbEH6uKCpcuu+sbSJth0taVXrxv/P5xiPmvyT5pFpfVTSM93dhA0wb0zZ4cHn/j bDGIrHYZZ4/TcNMdW7do8JI4xzt7kGrxZp/t4zGNw6lqihl345lsC0JNMFSfAbvLCVVv 7PKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718906283; x=1719511083; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=voUtFDbfyXxYSLuhMxY/5Es179PR05W0y6qbv62GFHo=; b=ae+E7S4O8ABfH8PzIJP1QN8Z+WeTLPB8Wn0dSbHtFlbo+b/qqj+i0cgRxOJSOJtJC6 y/2BaDKSLBk5S1amX0dHMwXe55xlCP6lV7xhiwtu+EXUTaeFhuJexKQUbu23V0drqTio A+dJJJzQN5q5fSwYRO23sDL7JIH5BytBi6k9+tE8hPWQSWWs8a+/pD+kQcG40s9dj++J iX2dvVpUwfFeRH2mdmotoqfVNyOYc4CygsrTn4RN79Ofz6DfP8imkCXdovSxiIIVDYEJ bTetZXoT5F4NzxmuckK9Fy1cY15zMQOx4+g/fFK6VJQfrvrpUt3XpHB3EVR/RCnt3kYA n/uQ== X-Forwarded-Encrypted: i=1; AJvYcCUmkGBsQSQqvBP68GGs5ZaA0lYXO4M9InULfEIU0J86BWE4s4waJwfaA275OqmmLBvPKZX8PD7GQ84lKUY56zPo6HRavre9fyyMqpEQ0TvdZrwVvic= X-Gm-Message-State: AOJu0YyWvy1nB/74Hko06nzWugYPRh83L4PFXaXJmxIp0DXpLg3o95w3 DofLmZNCBa0cuct1DtVgBxrltl82zoDmOvJZM8PCEIlKz9DxAh5U X-Google-Smtp-Source: AGHT+IFuFY8WsrUaBevsclcxusM/Sc7ZvIAfPxrnCGbXlGrdTSyKJ0ahnS/qbGoRPvPpSuP7Wt6hDQ== X-Received: by 2002:a05:6a00:4d07:b0:706:3514:2d6c with SMTP id d2e1a72fcca58-70635142dd9mr3899791b3a.29.1718906283409; Thu, 20 Jun 2024 10:58:03 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb6adb5sm12628100b3a.155.2024.06.20.10.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jun 2024 10:58:02 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Will Deacon , Robin Murphy , Joerg Roedel , Andy Gross , Bjorn Andersson , Konrad Dybcio , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org Cc: Yury Norov , Alexey Klimov , Bart Van Assche , Jan Kara , Linus Torvalds , Matthew Wilcox , Mirsad Todorovac , Rasmus Villemoes , Sergey Shtylyov Subject: [PATCH v4 19/40] iommu: optimize subsystem by using atomic find_bit() API Date: Thu, 20 Jun 2024 10:56:42 -0700 Message-ID: <20240620175703.605111-20-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240620175703.605111-1-yury.norov@gmail.com> References: <20240620175703.605111-1-yury.norov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240620_105804_785601_E61E0315 X-CRM114-Status: GOOD ( 15.33 ) 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 Simplify __arm_smmu_alloc_bitmap() and msm_iommu_alloc_ctx() by using a dedicated API, and make them nice one-liner wrappers. While here, refactor msm_iommu_attach_dev() and msm_iommu_alloc_ctx() so that error codes don't mismatch. Signed-off-by: Yury Norov --- drivers/iommu/arm/arm-smmu/arm-smmu.h | 11 +++-------- drivers/iommu/msm_iommu.c | 19 +++++-------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 4765c6945c34..c74d0300b64b 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -455,15 +456,9 @@ struct arm_smmu_impl { static inline int __arm_smmu_alloc_bitmap(unsigned long *map, int start, int end) { - int idx; + int idx = find_and_set_next_bit(map, end, start); - do { - idx = find_next_zero_bit(map, end, start); - if (idx == end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return idx < end ? idx : -ENOSPC; } static inline void __iomem *arm_smmu_page(struct arm_smmu_device *smmu, int n) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index 989e0869d805..4299e6a5b2ec 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -185,17 +186,9 @@ static const struct iommu_flush_ops msm_iommu_flush_ops = { .tlb_add_page = __flush_iotlb_page, }; -static int msm_iommu_alloc_ctx(unsigned long *map, int start, int end) +static int msm_iommu_alloc_ctx(struct msm_iommu_dev *iommu) { - int idx; - - do { - idx = find_next_zero_bit(map, end, start); - if (idx == end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return find_and_set_bit(iommu->context_map, iommu->ncb); } static void msm_iommu_free_ctx(unsigned long *map, int idx) @@ -418,10 +411,8 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) ret = -EEXIST; goto fail; } - master->num = - msm_iommu_alloc_ctx(iommu->context_map, - 0, iommu->ncb); - if (IS_ERR_VALUE(master->num)) { + master->num = msm_iommu_alloc_ctx(iommu); + if (master->num >= iommu->ncb) { ret = -ENODEV; goto fail; }