Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp87568lqr; Tue, 4 Jun 2024 22:43:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXycpo/o1kGZdarmFeMoHWWCt/t5ddMqMjwV2cbpvWv6C+NbYDraL2xxw+kAVnq/iSD4mvwqK89VG9CIvBr5Xq4q1JKHSzq1l4diV6Upw== X-Google-Smtp-Source: AGHT+IFJinWtgvSQ7hp2Eoerck+pivWt7ggcA6eUGCYI0GpnfePHF33uXyXORJJfttKbzGDh4lda X-Received: by 2002:a0d:dd88:0:b0:618:1034:f4ef with SMTP id 00721157ae682-62cbb4d6396mr15616347b3.16.1717566203976; Tue, 04 Jun 2024 22:43:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717566203; cv=pass; d=google.com; s=arc-20160816; b=rfgshPPMwLNFItWMQ/ApV3QHA9Jk0FFc8bpiACz1QaPujTCXaGsKVwH3N6fsaNybOV ttNkH7t4gVHczQshVlUOgtkb1Nl8JFovC52gECTDXz4zzcmf6B04XUzlAfYIy10XUVMI jgkCVjMc/zTn3lEgxxeEeiFpUE/X8C1wnK8QligJZrOSdrl3RIGAcdiLChHvyrJ1zIe3 dP3xIbYMzb6+x7UAY3rSNjmAPspXl2+UfNB4Z7qyjq3hQwUa5g8w91Dcgfuvf3ovoQkh F2p/7mXk5zroJfqBZkyoJEn4hC7kvXnK0LW+MaFClGH+MdEQCTlZHTggG8JI+q+55s1V EuDg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aBjOdC47mqVeNYrbSIGN2A/7SGRjWQavLlZ1uT7tR5I=; fh=1w3DLMv85iYBJkNFfPwPbipxfhw3GJYhEaGNtA+N0TY=; b=HSiv5RMgFWQjl+dzAeOxJmEhi96zYMppdCIkKKaAhsf/SrjmnsSHCtcbvUL3D4WLxA 3zkfuarKb0397NUo3neWMNCrp2mn/4aOZzUrPIb7BGtzEVqyve75wQoU06M4ihcgT8T3 OkIASr6olhAPlKDn75O2+m6JYGSCLGQYUP+7b0G43rUapjCSSnBN0ffsscSkW/Lxx0rd qBqiGzP7fkmbS4OqY3gyu3HW4490L9/EET1MsknDjrv9Uf1YR+mxj0mwpzzhkkRJz4by RPT9aFI2h7SPWjFtaI2MAPczerTgBANYuv9FWldhndWoJ9vDU7hp8se05lSJwqApkd6v FVYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=YJIbCAlf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-201632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201632-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6b00447f72esi14455746d6.401.2024.06.04.22.43.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 22:43:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=YJIbCAlf; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-201632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201632-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D55EA1C2183F for ; Wed, 5 Jun 2024 00:57:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2884747F; Wed, 5 Jun 2024 00:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YJIbCAlf" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B59FD6FB0; Wed, 5 Jun 2024 00:57:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717549049; cv=none; b=IhRwI1h6F3NOXm7Zgatua43iEhxiOz/0hRQTS05zbKNgp+BU7jWeRFuV4lB6MpX0S18oOSzBpzEidhYtec6it9k0HhqQQAvNDslUBzA/7Q/foegkz11rrHz0I3niJU5by6cRSb4m5vyO8DbYjtrH+g7wz5RYNPNZyIteIK/f4Iw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717549049; c=relaxed/simple; bh=+xrDUIF+EJ+GMGqVUKrY/AR4ZBF14Q2JYATUJuO/NAg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=uhIPoYZNPqqQUkOCBIBkLxU73rnxTjxVmLuzTkBcsSO0FCMMAEa2uxehO+SKwrbZy7exHp/pWLr4dFPOSm1vILVW21rZFsssx4HvCfY8xM7IjXlfLdxq6rS5993bfPpXcCJX5YOtXkghVMh0iWnNPDVDBw8PyhvXI2bQzQRlvu0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=YJIbCAlf; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=aBjOdC47mqVeNYrbSIGN2A/7SGRjWQavLlZ1uT7tR5I=; b=YJIbCAlfyAOt49uyvw1ZysTsMR z6dl0Jr0j0MnxqnB0gB4HRq3QfiZZfNLjRPN+0nHkPRR3VvTxi+2m9uNZ2NwTHesXUI5Z2QPV+Cxv qjxLjWvy6qxqotQl5DWGi89siuIr7gmIFqFNNKJHkMnKsoQz7QkrfwW32AHmWgbMBCwMHIfnseBgX h9HIUHo7yGPJ4AYbTF2hgiTlJVKdHzlSQdprG8uli3eE3JIIoN6FoISHT9MyJ78UazJqMjrqRsLKb DLYPf8IRdeNbpbA96kmoEL7UExbMiwr15JRjzwNiGwHhxEOcbvQf6g6vhrE5UkphXYr+sWA2KVsPN a0QNlCXA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sEexu-0000000FFDM-0FOy; Wed, 05 Jun 2024 00:57:22 +0000 Date: Wed, 5 Jun 2024 01:57:21 +0100 From: Matthew Wilcox To: Andrii Nakryiko Cc: linux-fsdevel@vger.kernel.org, brauner@kernel.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, gregkh@linuxfoundation.org, linux-mm@kvack.org, liam.howlett@oracle.com, surenb@google.com, rppt@kernel.org Subject: Re: [PATCH v3 1/9] mm: add find_vma()-like API but RCU protected and taking VMA lock Message-ID: References: <20240605002459.4091285-1-andrii@kernel.org> <20240605002459.4091285-2-andrii@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240605002459.4091285-2-andrii@kernel.org> On Tue, Jun 04, 2024 at 05:24:46PM -0700, Andrii Nakryiko wrote: > +/* > + * find_and_lock_vma_rcu() - Find and lock the VMA for a given address, or the > + * next VMA. Search is done under RCU protection, without taking or assuming > + * mmap_lock. Returned VMA is guaranteed to be stable and not isolated. You know this is supposed to be the _short_ description, right? Three lines is way too long. The full description goes between the arguments and the Return: line. > + * @mm: The mm_struct to check > + * @addr: The address > + * > + * Returns: The VMA associated with addr, or the next VMA. > + * May return %NULL in the case of no VMA at addr or above. > + * If the VMA is being modified and can't be locked, -EBUSY is returned. > + */ > +struct vm_area_struct *find_and_lock_vma_rcu(struct mm_struct *mm, > + unsigned long address) > +{ > + MA_STATE(mas, &mm->mm_mt, address, address); > + struct vm_area_struct *vma; > + int err; > + > + rcu_read_lock(); > +retry: > + vma = mas_find(&mas, ULONG_MAX); > + if (!vma) { > + err = 0; /* no VMA, return NULL */ > + goto inval; > + } > + > + if (!vma_start_read(vma)) { > + err = -EBUSY; > + goto inval; > + } > + > + /* > + * Check since vm_start/vm_end might change before we lock the VMA. > + * Note, unlike lock_vma_under_rcu() we are searching for VMA covering > + * address or the next one, so we only make sure VMA wasn't updated to > + * end before the address. > + */ > + if (unlikely(vma->vm_end <= address)) { > + err = -EBUSY; > + goto inval_end_read; > + } > + > + /* Check if the VMA got isolated after we found it */ > + if (vma->detached) { > + vma_end_read(vma); > + count_vm_vma_lock_event(VMA_LOCK_MISS); > + /* The area was replaced with another one */ Surely you need to mas_reset() before you goto retry? > + goto retry; > + }