From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37741C00140 for ; Tue, 26 Jul 2022 16:03:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7EE38E0002; Tue, 26 Jul 2022 12:03:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2E608E0001; Tue, 26 Jul 2022 12:03:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CFB68E0002; Tue, 26 Jul 2022 12:03:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7E5328E0001 for ; Tue, 26 Jul 2022 12:03:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 55287C12D9 for ; Tue, 26 Jul 2022 16:03:07 +0000 (UTC) X-FDA: 79729720014.27.2A5B0D0 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf04.hostedemail.com (Postfix) with ESMTP id 91256400A1 for ; Tue, 26 Jul 2022 16:03:04 +0000 (UTC) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26QFpamA012020; Tue, 26 Jul 2022 16:03:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to; s=pp1; bh=PAS2noWc49WM4lHDSxAdkEoVCyDOA+Vm1dQ3yb7PVsg=; b=RfCYWnZKw4mH3BcPzmsD1F2CFbNd1bG1O+hZ+HDQ3gk2pXwN14CtovQ4I/U/3Lgy5otY ToyoHvHnJTQ4b5pPYqXU9DUc4ezCVmVAViLMgGI1HR7eSGyZlo+khmiGkQ6pDSjfsw/K DlV//R3jgyVoQAc8KsMtF1YfoRXPRkelLN9WU3+olq6Qj3Jfo/1mZ4p+4qamFrWTxzom DuYKlxtD53ZJiOKIodHxAuPITHhdx9MNe6wgGPyhvZTQEVgyV0qkvzQKRAFB1zZsat5e 9uYULEH9pnQc1lihvy5eVmziopgWa9k2nMoJ7IS0/iwzFXIS1EJ8RwrNiSWhc8JKOpHv rw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hjk9h8c5a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Jul 2022 16:03:02 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 26QFt76o026857; Tue, 26 Jul 2022 16:03:02 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hjk9h8c3f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Jul 2022 16:03:02 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 26QG0BjA026037; Tue, 26 Jul 2022 16:02:59 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06fra.de.ibm.com with ESMTP id 3hg98fhdad-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Jul 2022 16:02:59 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 26QG2vCX17760594 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 26 Jul 2022 16:02:57 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2DD2111C052; Tue, 26 Jul 2022 16:02:57 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F77D11C050; Tue, 26 Jul 2022 16:02:56 +0000 (GMT) Received: from linux.ibm.com (unknown [9.145.85.51]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 26 Jul 2022 16:02:56 +0000 (GMT) Date: Tue, 26 Jul 2022 19:02:54 +0300 From: Mike Rapoport To: Nadav Amit Cc: Linux MM , Andrew Morton , Mike Kravetz , Hugh Dickins , Axel Rasmussen , Peter Xu , David Hildenbrand Subject: Re: [PATCH v2 2/5] userfaultfd: introduce access-likely mode for common operations Message-ID: References: <20220718114748.2623-1-namit@vmware.com> <20220718114748.2623-3-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-TM-AS-GCONF: 00 X-Proofpoint-GUID: fDdoFYRi_Q1K9iEtkVBOCOr6WnmsczhG X-Proofpoint-ORIG-GUID: b2Su6mZAt9EJSZ7dnQLK323OcHJQsRDg X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_04,2022-07-26_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 adultscore=0 clxscore=1015 mlxscore=0 suspectscore=0 spamscore=0 priorityscore=1501 phishscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207260062 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658851385; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PAS2noWc49WM4lHDSxAdkEoVCyDOA+Vm1dQ3yb7PVsg=; b=Gtj9+C3T1QWODnTLS13nyCSphtFIz5hzhN+WfwKeXMHFSWuIGof7vx2ZoylYBs6NQLNHzD wGyfybd8Tek6ei4LmMM9Dp0kD3mDNk6I7/6UqLWFOn6bEvmmEkO5iyCguUsps9FObkghQN X5684oQLVcZ84ssFWuFPZOORVGFZKVc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=RfCYWnZK; spf=pass (imf04.hostedemail.com: domain of rppt@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=rppt@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658851385; a=rsa-sha256; cv=none; b=gvN+t1MeXM4krIgitcjK7PAptmCVlVP4gEqEh5NfP8LqNratcM1eh1MllUpO7+gVxyqPKX XRC4tYFi0ua0hUHS7Wc0t9BUzlV24Gd+cIpEwbU46ChhQOynyUqI9797D/8BHY+Orva6vU +lN9Bp+FjsXn1LaskNDpG7mA8delWI0= X-Rspam-User: X-Stat-Signature: o6bn9dogqapthqrxc14yfmawtx35f5yr X-Rspamd-Queue-Id: 91256400A1 Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=RfCYWnZK; spf=pass (imf04.hostedemail.com: domain of rppt@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=rppt@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com X-Rspamd-Server: rspam10 X-HE-Tag: 1658851384-175850 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Jul 25, 2022 at 10:18:38AM -0700, Nadav Amit wrote: > > > On Jul 23, 2022, at 2:16 AM, Mike Rapoport wrote: > > > > On Mon, Jul 18, 2022 at 04:47:45AM -0700, Nadav Amit wrote: > >> From: Nadav Amit > >> > >> Introduce access-hints in userfaultfd. The expectation is that userspace > >> would set access-hints when a page-fault occurred on a page and would > >> not provide the access-hint on prefaulted memory. The exact behavior of > >> the kernel in regard to the hints would not be part of userfaultfd api. > >> > >> At this time the use of the access-hint is only in setting access-bit > >> similarly to the way it is done in do_set_pte(). In x86, currently PTEs > >> are always marked as young, including prefetched ones. But on arm64, > >> PTEs would be marked as old (when access bit is supported). > >> > >> If access hints are not enabled, the kernel would behave as if the > >> access-hint was provided for backward compatibility. > >> > >> Cc: Mike Kravetz > >> Cc: Hugh Dickins > >> Cc: Andrew Morton > >> Cc: Axel Rasmussen > >> Cc: Peter Xu > >> Cc: David Hildenbrand > >> Cc: Mike Rapoport > >> Signed-off-by: Nadav Amit > >> --- > >> fs/userfaultfd.c | 39 ++++++++++++++++++++++++++++---- > >> include/linux/userfaultfd_k.h | 1 + > >> include/uapi/linux/userfaultfd.h | 20 +++++++++++++++- > >> mm/internal.h | 13 +++++++++++ > >> mm/memory.c | 12 ---------- > >> mm/userfaultfd.c | 11 +++++++-- > >> 6 files changed, 77 insertions(+), 19 deletions(-) > >> > >> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c > >> index 2ae24327beec..8d8792b27c53 100644 > >> --- a/fs/userfaultfd.c > >> +++ b/fs/userfaultfd.c > >> @@ -1708,13 +1708,21 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx, > >> ret = -EINVAL; > >> if (uffdio_copy.src + uffdio_copy.len <= uffdio_copy.src) > >> goto out; > >> - if (uffdio_copy.mode & ~(UFFDIO_COPY_MODE_DONTWAKE|UFFDIO_COPY_MODE_WP)) > >> + if (uffdio_copy.mode & ~(UFFDIO_COPY_MODE_DONTWAKE|UFFDIO_COPY_MODE_WP| > >> + UFFDIO_COPY_MODE_ACCESS_LIKELY)) > >> goto out; > >> > >> mode_wp = uffdio_copy.mode & UFFDIO_COPY_MODE_WP; > >> > >> uffd_flags = mode_wp ? UFFD_FLAGS_WP : UFFD_FLAGS_NONE; > >> > >> + if (ctx->features & UFFD_FEATURE_ACCESS_HINTS) { > >> + if (uffdio_copy.mode & UFFDIO_COPY_MODE_ACCESS_LIKELY) > >> + uffd_flags |= UFFD_FLAGS_ACCESS_LIKELY; > >> + } else { > >> + uffd_flags |= UFFD_FLAGS_ACCESS_LIKELY; > >> + } > >> + > > > > This is quite a construct and it gets more complex in the following > > patches. How about making it to a static inline function? > > Possible. There is another option though. I think it would have been > much cleaner if some flags were in common offsets in the different > “mode” fields. It might be too late for some fields (WP), but I can > put these the ACCESS/WRITE fields in the the high bits in fixed > place for all modes, which would allow to at least reuse the logic. So unless I'm missing something it'll be if (ctx->features & UFFD_FEATURE_ACCESS_HINTS) uffd_flags |= (uffdio_copy.mode & UFFDIO_COPY_MODE_ACCESS_MASK); else uffd_flags |= UFFD_FLAGS_ACCESS_MASK; I still think it's worth wrapping it in static inline with a comments about common offsets for 'if' clause and backward compatibility for 'else' clause. > Is that ok? > -- Sincerely yours, Mike.