Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1661723pxb; Thu, 7 Oct 2021 12:18:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5vJSVf9ytNh4Eg9nJMCr40ScmbQ1jihGYkNInsZ8G6N6Hfy8nUAjrQrexGYwH2RM6AP8G X-Received: by 2002:a05:6a00:c81:b029:30e:21bf:4c15 with SMTP id a1-20020a056a000c81b029030e21bf4c15mr6036650pfv.70.1633634305021; Thu, 07 Oct 2021 12:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633634305; cv=none; d=google.com; s=arc-20160816; b=cycLXA5RzoT3/Tai6PtT7pgzygaqCV2AmTE5pzXr8gqK35dBLqEwiYrDnSohgeG2Dj BfzkM/cKz5tZBB+yMg9JRx5PbZnVO+EjobEPZn3ZKD/oIsznmGU+wGWJIqhls+sewHwu eNfXGzFl/DiIRbgX2kKs1Z1HCWp0sqOA7uBxwr8ZbtbH/FPNbctH/q9BAwB9oqZnhGOc nqM4YTWmEmBdvAJS9dmcxvzdaFUL/CW/Lhny1j3N8a7DT3GjZ5eCANimt3CFD8SYw+TG 7UYT1VXDVi+DFWpb1j+5SW0XAnWfjiMXzAZMobPy8YLQiYnwVjye+ffZz5jT+O3gRvu8 g3FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=yGrdZURdyyQHH4I6fQnJVysH/ia90SNkjihwgft55Yw=; b=AjQO8Mz5cptC+KBjBhf++CNmApIU6+mcvt2fjSN494o8GuprUvjOyYRT2KqFLG7iAm 4+nRrare6DYcynn/GeHuW9ViJ0zvq1uIpViLGL/iDj9jz9JpXapNEViA1+wYjl3j4+y5 LKVwwclntSkl7vE9DER2jkzGHLPxdKB8BYZnZhqm/eIwqcrMwlEiIo/mSDSPvjayPfjB bNAHOhWyBWc52JvNS04l6oeca6+jxij8tR2FGWd646eUrGI3fSk1aiqz7pF+Qd7AQJjJ dVAHD6GDoTYHcjZ/xAvuBT+gP3HpxCShPmpR59K+/DuknZ4JHjPWeeyq6qbhtp55YQ0i kAlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E7OLqO5o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ij6si232634plb.350.2021.10.07.12.18.11; Thu, 07 Oct 2021 12:18:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E7OLqO5o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243874AbhJGTSf (ORCPT + 99 others); Thu, 7 Oct 2021 15:18:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233889AbhJGTSe (ORCPT ); Thu, 7 Oct 2021 15:18:34 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6D79C061755 for ; Thu, 7 Oct 2021 12:16:40 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id n8so27363928lfk.6 for ; Thu, 07 Oct 2021 12:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yGrdZURdyyQHH4I6fQnJVysH/ia90SNkjihwgft55Yw=; b=E7OLqO5oGH3PxMmtZPsYgd/cTqyTh9mX8w1VAUI/FW2Rf7o1rbJl9qcoKCF9mKbD4V sjt15yNOsZ8jrRq4TsqaZGOElRKcGV9UZbL27JYDHZgddxkMg7kl6c4wtx1gKYZL5R7Q Ivjqh1OdEv82usQ7O+uCy9Jm9eUXk/eHuhanHL44HPAkxXDnoZrvs8sbO/mf7fBS3HJK VlpPDKLdQ8wUNiA60IPaV8xNZq+iBCbabesw56Ba8WFKCqPVl3rnTIbNzdm8tl9wTQ2P HCFSDI9GaDgMviDg57N9XlZg0CCoaskxSo5jx6d1uLR06Q3hFQQNcCewmXBwGJChk5JC tfmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=yGrdZURdyyQHH4I6fQnJVysH/ia90SNkjihwgft55Yw=; b=kry8DQNjH9ebjM6m3IgeUcy2xh6/qfaNKI0ZN1aeIdwWDIjGwiPmCCKkXoBfyVyxCv EuoaJvYuQj8qeApca3UK2gZbU9JZeiXm/3AEINBtBMCHihIzgOwLyLwwNsx33Zr0jytd ChwQnynk5gOswBu/Tqfj4u3sXICsCnXq44dQYZmVKpJVv/l/i2OaaaQN9Al7UQknAQSu lXY27kIjbDj4wV0Dh/D6Oh/TJLKbI9s8UFhqsNHeQjJhvgQMDycbnGkmsBQPJ/9aB2mv xcbbc3msyffqyNRkY6VLw6rSiG6Fkp3N/cefeYoQDkzY2yaqd5OFkhL8PovXqOedgYce CZJw== X-Gm-Message-State: AOAM5338S9pnLtSFpufbvDCDEymQbCRTmB0XMjhergzq3oR8e+mL1BCC VFPP6elk+6hWtacyctdTkInfKw== X-Received: by 2002:a05:6512:3b90:: with SMTP id g16mr692856lfv.216.1633634198810; Thu, 07 Oct 2021 12:16:38 -0700 (PDT) Received: from localhost (c-9b28e555.07-21-73746f28.bbcust.telenor.se. [85.229.40.155]) by smtp.gmail.com with ESMTPSA id t17sm17599lfl.223.2021.10.07.12.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 12:16:38 -0700 (PDT) From: Anders Roxell To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, viresh.kumar@linaro.org, Anders Roxell Subject: [RFC PATCH] fs: proc: task_mmu: fix sparse warnings Date: Thu, 7 Oct 2021 21:16:36 +0200 Message-Id: <20211007191636.541041-1-anders.roxell@linaro.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When building the kernel with sparse enabled 'C=1' the following warnings can be seen: fs/proc/task_mmu.c:587:17: warning: context imbalance in 'smaps_pte_range' - unexpected unlock fs/proc/task_mmu.c:1145:28: warning: context imbalance in 'clear_refs_pte_range' - unexpected unlock fs/proc/task_mmu.c:1473:28: warning: context imbalance in 'pagemap_pmd_range' - unexpected unlock fs/proc/task_mmu.c:1811:28: warning: context imbalance in 'gather_pte_stats' - unexpected unlock Rework to add __acquire() and __release() to tell sparse that it is all good. Signed-off-by: Anders Roxell --- fs/proc/task_mmu.c | 31 +++++++++++++++++++++++++++++++ mm/huge_memory.c | 4 +++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index ad667dbc96f5..6b702c030802 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -584,6 +584,13 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, ptl = pmd_trans_huge_lock(pmd, vma); if (ptl) { + /* + * Fake out sparse. + * The pmd_lock are held in pmd_trans_huge_lock() and if we + * get in here we have to unlock. We tell sparse that + * everyting is as it should with the __acquire() directive. + */ + __acquire(ptl); smaps_pmd_entry(pmd, addr, walk); spin_unlock(ptl); goto out; @@ -1127,6 +1134,14 @@ static int clear_refs_pte_range(pmd_t *pmd, unsigned long addr, ptl = pmd_trans_huge_lock(pmd, vma); if (ptl) { + /* + * Fake out sparse. + * The pmd_lock are held in pmd_trans_huge_lock() and if we + * get in here we have to unlock. We tell sparse that + * everyting is as it should with the __acquire() directive. + */ + __acquire(ptl); + if (cp->type == CLEAR_REFS_SOFT_DIRTY) { clear_soft_dirty_pmd(vma, addr, pmd); goto out; @@ -1418,6 +1433,14 @@ static int pagemap_pmd_range(pmd_t *pmdp, unsigned long addr, unsigned long end, pmd_t pmd = *pmdp; struct page *page = NULL; + /* + * Fake out sparse. + * The pmd_lock are held in pmd_trans_huge_lock() and if we + * get in here we have to unlock. We tell sparse that + * everyting is as it should with the __acquire() directive. + */ + __acquire(ptl); + if (vma->vm_flags & VM_SOFTDIRTY) flags |= PM_SOFT_DIRTY; @@ -1804,6 +1827,14 @@ static int gather_pte_stats(pmd_t *pmd, unsigned long addr, if (ptl) { struct page *page; + /* + * Fake out sparse. + * The pmd_lock are held in pmd_trans_huge_lock() and if we + * get in here we have to unlock. We tell sparse that + * everyting is as it should with the __acquire() directive. + */ + __acquire(ptl); + page = can_gather_numa_stats_pmd(*pmd, vma, addr); if (page) gather_stats(page, md, pmd_dirty(*pmd), diff --git a/mm/huge_memory.c b/mm/huge_memory.c index e5ea5f775d5c..c873bf5947ae 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1833,8 +1833,10 @@ spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma) spinlock_t *ptl; ptl = pmd_lock(vma->vm_mm, pmd); if (likely(is_swap_pmd(*pmd) || pmd_trans_huge(*pmd) || - pmd_devmap(*pmd))) + pmd_devmap(*pmd))) { + __release(ptl); /* fake out sparse */ return ptl; + } spin_unlock(ptl); return NULL; } -- 2.33.0