Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp92330rdh; Tue, 13 Feb 2024 10:16:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCViqH1nI6TRV6dcfVkPxeHkqd+nG7Q7xLDrMVFSo4jBpRMjIJiYh8xBO9pAPNsqUdHDIBGqSXExNzCIJ2U3a/qtGStZ0tbY5UrCnCdd8g== X-Google-Smtp-Source: AGHT+IG1vGj9dsv4tIlvj7tQqaIZuJrqmV7QHCBgGSAnbOJbZ59A+1UtaJYBnfdbGwE+29p19Xjx X-Received: by 2002:a17:903:2347:b0:1d9:c876:b82f with SMTP id c7-20020a170903234700b001d9c876b82fmr372840plh.30.1707848186447; Tue, 13 Feb 2024 10:16:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707848186; cv=pass; d=google.com; s=arc-20160816; b=sDwbZHLI/g6z08Fdx53+ga55vXszqyo7qZJstdQjzn+kMUKMSNHOPYhcb0IwX8tmy2 3aFSP6QNjiCbiV1Fkr7k91OC8bcv0ubADxUtMEhkBlljzxP7jXq+1eWZYdIeK6a+s6bB ysMaqYtJzchKdSSuDE5IilHBxEaQiOEjStoggylQVWGZv+4n5k+CzhzXOY//vow5klUR Qn/RHcADjjqf+P//JW3VuSv/94QcTCfJ4oxlaRg6UQvdAEZKBsyxkdRnxNU1FjOABmsK h44oC4PaE+ZSizArch7eDMBOZDzswxAPNeFHrn5ziAIhMOuuRpvleLvO6DTsSUoWUEt1 UOhQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=21wqIURVqzFnw45KjAoFtF/+uk4paqLSEGTh7Vx6QVg=; fh=gBwIBYq8vNJ85mMWUDxCUSvYZ64B6j5nC0KfIfPLPzs=; b=dsV+WbXqbFrIQqsqD+51hZ6/KRaAtE/6CJpE1i87b0JxwlV4Y2VHBtV2vsSKGbD0IK uGrH58DsRR9el/5MU+WLTXgk7qWW7lcSjapQPNov6A7WV7p7ekU2Fi3zuAFDQZHAvBQD D+sr8hXOI9Qpx0g2dLwtargA6tRv1f7Smb813oYQJq9XYvp4OHynb5QRFm/Wjb6pst3R dl5C0jUn74mSvKnahNLas7I3EtartH8BdqaRSFHV8Sjv2wAthUnOE+qpks25VrOcxnA2 0BTbS5OJ9GiDpdm3CUAN+ZvKZOVfyqQjrWBuMtnU3J3OtQX11/7Y7CsSCMuwpNJ2T30g lP4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="aCMpu/EB"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64065-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCVJAJOLt5JmIqgdYTW3VvevCB9lbvP2w/C8sP6YxqdNOlB08IYnAS0Z2rY9Tq3AIGJpVLU6bRMxbxXaPb4tTQEw8vIdlfKO3n2MY5R66g== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m4-20020a170902db0400b001d960a13feesi2367748plx.544.2024.02.13.10.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 10:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="aCMpu/EB"; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64065-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64065-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 49C152863C6 for ; Tue, 13 Feb 2024 18:15:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 53831605D5; Tue, 13 Feb 2024 18:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aCMpu/EB" Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEC0E605B3 for ; Tue, 13 Feb 2024 18:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707848094; cv=none; b=qv+Sd4czsBVNdOZUr8dAArr7SqXaikH4Zytz7zN//30V5vqI67+c4/D8hCOjSMAxGq7Fl2UDYLMsfQBYQPBovwMVADrNy5TLA0WWM0Rc79A/uxRC0eHOVS+OsczTbtHA1dim0sGrkqHKmpgLfqT9F2GZe8+oOt7aL3UHzmaUjuA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707848094; c=relaxed/simple; bh=pFTVmcL+7AKQTzSgLeowHwXQTcO1RcbCaNlkKYs1gnI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Content-Type; b=T4hdkq9RacuEBuQQsBm9ge571XqlFn+cmax+A88eGFUWYzAxk3jbJRWYy6kQ1MG2VxECDYSYpapuV+RfiJk9m05D1MwCVn0flLy+tK2x8xOkUztsyJCWwwwNszYVcp0DMx1wiWnYvcOfyHjgogW8QHB8vPLjVCNrNbwbCQNHwSM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aCMpu/EB; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-411a6ada28dso8891695e9.3 for ; Tue, 13 Feb 2024 10:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707848091; x=1708452891; darn=vger.kernel.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=21wqIURVqzFnw45KjAoFtF/+uk4paqLSEGTh7Vx6QVg=; b=aCMpu/EBJ6sZhv5YK9hDRBnrW7Kxu1zoc+KdL8/2ckZLPgGMElbnoAfoG5YwvvwAh4 jZaB0+472a7OmuyDKSXfBEEnADpGBxI9OT70szgnBB4170/gsVFt85AGn/nq24CzIMPi 7fD7H0PXI3W9dkWFIkggSreaPckOELEu8hUeEKauPa1qcXcSBXmLLS7P//8yRTqZbmAQ uVWjJMbIFnULXwecfYCbbAgu1IY33Hs9d9wGqHtLrFoTYKTq1SvAIfY5itidGlZkrtSA noPKKvuQFIBVSk9ZJ4o02DuuoliCCrq6zujgMtD+MyyTDh5WFHbRGHBAbjikyj+7P1HP mhUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707848091; x=1708452891; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=21wqIURVqzFnw45KjAoFtF/+uk4paqLSEGTh7Vx6QVg=; b=mM5sb/KMgNAfSxfXgmd16y3xWPXQtIrbwzJezi3wNHEYkvHd5n7J659Sj0dVPBXa5L Vgzo+yXG/1RTl1CMbX9uBMmrFULU3n12HAUVmn96u32H2gljx/8K952xMJMlPIdgHXYC xOPJwJK2JslqZ0kZAj71wQu4AMnKHTdcOGY7onbCVjMUXjQD8oEoNKAw5vMXHA/rYL0J r09+cC1tXMaIyipaVZ8DT2Jf7ht5ZSk5IbJwI6vwj3dXxCCU5p5W6TfUxRe8qgE1dXwe zJCJXAXkbXahJbfTOoj/ghAdij+tX8RDqK4JPqFIq7ZmlnyH2VwtvCoW2vJNEqSgEIkA ZXhg== X-Forwarded-Encrypted: i=1; AJvYcCUftX6uekPq9MHOrZw9DJCsXUs4UvjwomjssXI3v7jc/M2ibDT4ZM0OfSPjIWLQ79+8LiLy6EG35ekvH3cTTcT9F4us3uc4aDDD/Qmk X-Gm-Message-State: AOJu0Yxtj0P7XjoJEgpu9CiXMiz1PgIvarxjKvZ1mXiskczEHRfJ3lX4 xv9kbkNhxfaiFGnxpd3UyAncaFHfkEu5FmX3l2FHXiQdq6Xn5uzoS5aXF8h+qpAPBZc0I3WOmws NWSBpTtY6/b3CyOE1iQZUopk2KnvTG2JFqo9u X-Received: by 2002:a05:600c:1d1f:b0:40e:fb76:5344 with SMTP id l31-20020a05600c1d1f00b0040efb765344mr313051wms.11.1707848090744; Tue, 13 Feb 2024 10:14:50 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240213001920.3551772-1-lokeshgidra@google.com> <20240213001920.3551772-4-lokeshgidra@google.com> <20240213033307.zbhrpjigco7vl56z@revolver> <20240213170609.s3queephdyxzrz7j@revolver> In-Reply-To: <20240213170609.s3queephdyxzrz7j@revolver> From: Lokesh Gidra Date: Tue, 13 Feb 2024 10:14:38 -0800 Message-ID: Subject: Re: [PATCH v5 3/3] userfaultfd: use per-vma locks in userfaultfd operations To: "Liam R. Howlett" , Lokesh Gidra , akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, selinux@vger.kernel.org, surenb@google.com, kernel-team@android.com, aarcange@redhat.com, peterx@redhat.com, david@redhat.com, axelrasmussen@google.com, bgeffon@google.com, willy@infradead.org, jannh@google.com, kaleshsingh@google.com, ngeoffray@google.com, timmurray@google.com, rppt@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 13, 2024 at 9:06=E2=80=AFAM Liam R. Howlett wrote: > > * Lokesh Gidra [240213 06:25]: > > On Mon, Feb 12, 2024 at 7:33=E2=80=AFPM Liam R. Howlett wrote: > > > > > > * Lokesh Gidra [240212 19:19]: > > > > All userfaultfd operations, except write-protect, opportunistically= use > > > > per-vma locks to lock vmas. On failure, attempt again inside mmap_l= ock > > > > critical section. > > > > > > > > Write-protect operation requires mmap_lock as it iterates over mult= iple > > > > vmas. > > > > > > > > Signed-off-by: Lokesh Gidra > > > > --- > > > > fs/userfaultfd.c | 13 +- > > > > include/linux/userfaultfd_k.h | 5 +- > > > > mm/userfaultfd.c | 392 ++++++++++++++++++++++++++----= ---- > > > > 3 files changed, 312 insertions(+), 98 deletions(-) > > > > > > > ... > > I just remembered an issue with the mmap tree that exists today that you > needs to be accounted for in this change. > > If you hit a NULL VMA, you need to fall back to the mmap_lock() scenario > today. Unless I'm missing something, isn't that already handled in the patch? We get the VMA outside mmap_lock critical section only via lock_vma_under_rcu() (in lock_vma() and find_and_lock_vmas()) and in both cases if we get NULL in return, we retry in mmap_lock critical section with vma_lookup(). Wouldn't that suffice? > > This is a necessity to avoid a race of removal/replacement of a VMA in > the mmap(MAP_FIXED) case. In this case, we munmap() prior to mmap()'ing > an area - which means you could see a NULL when there never should have > been a null. > > Although this would be exceedingly rare, you need to handle this case. > > Sorry I missed this earlier, > Liam