Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp763003ybl; Fri, 6 Dec 2019 05:56:38 -0800 (PST) X-Google-Smtp-Source: APXvYqzRtywcHF6VeJNKbHQ7NymeDvi0VrG7GCIvX32XTn+xD1VRsXtfJDfpqVT9a/uXxMwOKV9w X-Received: by 2002:a9d:6b06:: with SMTP id g6mr10922037otp.93.1575640598553; Fri, 06 Dec 2019 05:56:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575640598; cv=none; d=google.com; s=arc-20160816; b=UKC3nNEuZTSShHbZTwGjXIhgqu4PWqP8lAAkX6rAe1GbsxsAczpIdRs+7jXe2gdUzH skw2yydITKWrlPB1PhxEBmhBnKIzkwutq+Sa6ab8AULjVepd0eY0uaEkxo+qX3f/p9cV nB/+ViTPIqveVcFZ+PAbrQFoNnL2SGielb11ijmgm1JBqhoo3TXvtlEy+EP2fS/2Sk7Q Bz2KkbvykioViTp8nQz5vMwPBEFWquch3Ih9w6GANMNG6HLGfGtwESDkpyE7FvDTbvfO reUEp2Tsl8l0b4eW10Gk0WPJkzrPo5xh35SiWpT+WKKf1S3ZyBQQQsYooSwbHZM/LjUY QfEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=OQzTVCtQxH3pTr2CC/OgVX9xeRauBvU+VtgHwnCZm8Q=; b=ymn/lJeBHi0AiaCuaNsEHJFYimRWvCercLkaiUtDKMKo5uaJ0KRvgga2DLKEZnpum2 Ns2gfHROYC2DCzXDkS2XOoYJklWWV7NpEHUedncJnEM9kl4VHg5pQKrZS72fduoabBcR bCW30G9J9b2EvMIzVpKoFf0bc1FSIYzo+/iFrxgBLtX+l/SOLLf9O/Q90t9ncm3rPdPY O1jzAxlhc1Q+WF2E6YLb4QrBkW+wnj02DRMThnGp29vAwpOhH+nYc2Rbv/U6u6WY7vAv Vz9zOfnQ6TbCILT76nWAaZg+/m/BhYghzt2IuCVv1XcTQs0E/LEQojjoX7WHvQyjYGt6 I9ag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p16si2291045oto.287.2019.12.06.05.56.26; Fri, 06 Dec 2019 05:56:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726894AbfLFNyg (ORCPT + 99 others); Fri, 6 Dec 2019 08:54:36 -0500 Received: from foss.arm.com ([217.140.110.172]:44782 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726505AbfLFNyW (ORCPT ); Fri, 6 Dec 2019 08:54:22 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D42ED1FB; Fri, 6 Dec 2019 05:54:21 -0800 (PST) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 54C263F718; Fri, 6 Dec 2019 05:54:19 -0800 (PST) From: Steven Price To: Andrew Morton , linux-mm@kvack.org Cc: Steven Price , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Dave Hansen , Ingo Molnar , James Morse , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Peter Zijlstra , Thomas Gleixner , Will Deacon , x86@kernel.org, "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Rutland , "Liang, Kan" Subject: [PATCH v16 13/25] mm: pagewalk: Don't lock PTEs for walk_page_range_novma() Date: Fri, 6 Dec 2019 13:53:04 +0000 Message-Id: <20191206135316.47703-14-steven.price@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191206135316.47703-1-steven.price@arm.com> References: <20191206135316.47703-1-steven.price@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org walk_page_range_novma() can be used to walk page tables or the kernel or for firmware. These page tables may contain entries that are not backed by a struct page and so it isn't (in general) possible to take the PTE lock for the pte_entry() callback. So update walk_pte_range() to only take the lock when no_vma==false and add a comment explaining the difference to walk_page_range_novma(). Signed-off-by: Steven Price --- mm/pagewalk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/pagewalk.c b/mm/pagewalk.c index efa464cf079b..1b9a3ba24c51 100644 --- a/mm/pagewalk.c +++ b/mm/pagewalk.c @@ -10,9 +10,10 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, pte_t *pte; int err = 0; const struct mm_walk_ops *ops = walk->ops; - spinlock_t *ptl; + spinlock_t *uninitialized_var(ptl); - pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); + pte = walk->no_vma ? pte_offset_map(pmd, addr) : + pte_offset_map_lock(walk->mm, pmd, addr, &ptl); for (;;) { err = ops->pte_entry(pte, addr, addr + PAGE_SIZE, walk); if (err) @@ -23,7 +24,9 @@ static int walk_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, pte++; } - pte_unmap_unlock(pte, ptl); + if (!walk->no_vma) + spin_unlock(ptl); + pte_unmap(pte); return err; } @@ -383,6 +386,12 @@ int walk_page_range(struct mm_struct *mm, unsigned long start, return err; } +/* + * Similar to walk_page_range() but can walk any page tables even if they are + * not backed by VMAs. Because 'unusual' entries may be walked this function + * will also not lock the PTEs for the pte_entry() callback. This is useful for + * walking the kernel pages tables or page tables for firmware. + */ int walk_page_range_novma(struct mm_struct *mm, unsigned long start, unsigned long end, const struct mm_walk_ops *ops, void *private) -- 2.20.1