From patchwork Tue Apr 23 19:28:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 13640591 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 4A01BC04FFE for ; Tue, 23 Apr 2024 19:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA76F6B017B; Tue, 23 Apr 2024 15:28:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B097F6B017D; Tue, 23 Apr 2024 15:28:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95C5B6B017E; Tue, 23 Apr 2024 15:28:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7337F6B017B for ; Tue, 23 Apr 2024 15:28:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 26AEB40F94 for ; Tue, 23 Apr 2024 19:28:36 +0000 (UTC) X-FDA: 82041783432.15.7ED1330 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf25.hostedemail.com (Postfix) with ESMTP id 4057BA0006 for ; Tue, 23 Apr 2024 19:28:34 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=RGvhfcGH; spf=pass (imf25.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713900514; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XEOBuREQJ368TToeAeD7bKJjC+GLUrWOkGfeVbtkYk8=; b=5FvDeSn7lbs10IOhAi7exNHGchE+TwhB6XzC36wpnvCcnNIUxzJ7nHr4dHb3Csf4qoaVbn FOkOAhmB2y589jPUecos5h+5BheaHwEgWLB8zqrcSOa4s0JwZffHcqzkm65TC1I8I+RScn 4qHl+Gpb/0OXzUzTYM0FW9Ph2dhZWBc= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=RGvhfcGH; spf=pass (imf25.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.210.179 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713900514; a=rsa-sha256; cv=none; b=DWBMDqFNeBJLfwXYS62SzH0oxyHpOw5X98cJ2sLsevwM6WbtLj6khB0wOqjza8zxVDuRGp Ib9SeIAjtzRtA8Zr7az4xGw1iTxWn01ihG1FIUwHBdAaQ6+jfD9iZf9VEWItZiUtS5Nipe sk0QI+j6WlBUl30VGNur03JUC5xNPGk= Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6f0aeee172dso146077b3a.1 for ; Tue, 23 Apr 2024 12:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1713900513; x=1714505313; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XEOBuREQJ368TToeAeD7bKJjC+GLUrWOkGfeVbtkYk8=; b=RGvhfcGHqSuWCdHuH1nLc7h+I/0pVTGAz5KeNkrLUFvQZF1fzBgfb4E1o+ihT6I0kq KCsdyEyS6jIC/PCzMUsABTXdgVjOI1w/qeBtXP7dscbAwPwnY46cIRZq6J0fwSwLNcil FOQLO8pwt5ALzruQoUbQwPtqMqxvNTmVTEGGI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713900513; x=1714505313; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XEOBuREQJ368TToeAeD7bKJjC+GLUrWOkGfeVbtkYk8=; b=Vk9brFwB2UKm527A4HSzICfiABYKnRSXwxloUmEKwyY/k9Gx1/j+UKaNRKZW7/4w/V k10CuvF9ycI1Re3IVtLIqK3HSlnkwP08NjZms1D9gQI4xF9u9bh0YSHzGfMCziBbMfgc caKfHaW5nT8NsI7RZ3jLiau4Ldf7l5pEvc5RWHdos7+cUlNAXfN0uM9ifVJKzecycKgg 6CmLNO4Y2hsQkPlXBJ3S8Nfk9QZlIeqmxZICaveRvWIAhtpMzRIjEILhAT75LzM+ZHhC xpEq7j2TH+BEn8YV1dALVT+mz1lnYTIg/lUg/HsH7wvq3usga0CWzkzEGFX5M7592+8e fN1g== X-Forwarded-Encrypted: i=1; AJvYcCUgbHqtoWsoKltrqNzrThXHjYZzKSYdUTjB0kPfVNt1iTbxVGVe6B28RXx2odouXyOCF9oqV2lnl6VgtduOzp/5K/Y= X-Gm-Message-State: AOJu0YzKeyVuwRi5qea6TEfTtE/25iTDXgwhI856yxHlA8kINkZQP8L4 0MbytEFuMFIaWZOfSqqKmxodb5Ncr6Ew6SB3J+WoisLpAksDasLG+WPQvYS6AiEKvvZwquRVkRs = X-Google-Smtp-Source: AGHT+IFUpaXaTakm4yI6/L52VsdiGQgNiJ1sgdGRCdzy04mXVCbJ8tWKoHrdU+IwCbwDWAUwOgOY8g== X-Received: by 2002:a05:6a00:1825:b0:6ec:fa34:34ab with SMTP id y37-20020a056a00182500b006ecfa3434abmr633901pfa.9.1713900512865; Tue, 23 Apr 2024 12:28:32 -0700 (PDT) Received: from localhost (238.76.127.34.bc.googleusercontent.com. [34.127.76.238]) by smtp.gmail.com with UTF8SMTPSA id t15-20020aa78f8f000000b006ed92b011desm10008324pfs.169.2024.04.23.12.28.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Apr 2024 12:28:32 -0700 (PDT) From: jeffxu@chromium.org To: akpm@linux-foundation.org, pedro.falcato@gmail.com Cc: jeffxu@google.com, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Jeff Xu Subject: [PATCH v1 1/1] mseal: Add branch prediction hint. Date: Tue, 23 Apr 2024 19:28:25 +0000 Message-ID: <20240423192825.1273679-2-jeffxu@chromium.org> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog In-Reply-To: <20240423192825.1273679-1-jeffxu@chromium.org> References: <20240423192825.1273679-1-jeffxu@chromium.org> MIME-Version: 1.0 X-Stat-Signature: r6tt91e4torudt994fu73117c44msjyf X-Rspamd-Queue-Id: 4057BA0006 X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1713900514-114973 X-HE-Meta: U2FsdGVkX1/ovWc88P9IEXs6mbAL+uVfw7d/bBhwSx7wLckMKjGu4xfKTkiRSpKoCX/pc599tXIhQ62RmpupuwxFhr/KeMZQ/jRPqL0SnacXoDj+w37Z7lqfkxPPxAZK1dpodc+3PV/AM7asJsS7Zou0C0OneFw//UySSCY0X1R34Ny6pF5aqm1kOb2IfdL1bxnKCFZj7/X5WsniEDy2xSMj1Y+N2wdrrVF8J8AVThWcCNFl+4iqhztY1Hn5GRmH7iuppIDYPrGfT32w9TPF/ePvfQ841iQ0n8IDUtQNxRJC8It6NfHQALXZ41dN30NGfjnop0oRaRDhbShXz11BIiWXZppIWUv50/HXneCg3hozRlKvAEqCR8Bntl9flZNFk4sXaXQSQBD9AAzCaqnJ+y3YZXt4kxPu+sS5IT1flvztayXv/fuE+aN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-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Jeff Xu It is unlikely that application calls mm syscall, such as mprotect, on already sealed mappings, adding branch prediction hint. Signed-off-by: Jeff Xu Suggested-by: Pedro Falcato --- mm/madvise.c | 2 +- mm/mmap.c | 4 ++-- mm/mprotect.c | 2 +- mm/mremap.c | 4 ++-- mm/mseal.c | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index f7d589534e82..ea2e4f6981e2 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1442,7 +1442,7 @@ int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int beh * Check if the address range is sealed for do_madvise(). * can_modify_mm_madv assumes we have acquired the lock on MM. */ - if (!can_modify_mm_madv(mm, start, end, behavior)) { + if (unlikely(!can_modify_mm_madv(mm, start, end, behavior))) { error = -EPERM; goto out; } diff --git a/mm/mmap.c b/mm/mmap.c index 4b80076c319e..6bc0b35ee1f9 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2697,7 +2697,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, * Prevent unmapping a sealed VMA. * can_modify_mm assumes we have acquired the lock on MM. */ - if (!can_modify_mm(mm, start, end)) + if (unlikely(!can_modify_mm(mm, start, end))) return -EPERM; /* arch_unmap() might do unmaps itself. */ @@ -3120,7 +3120,7 @@ int do_vma_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, * Prevent unmapping a sealed VMA. * can_modify_mm assumes we have acquired the lock on MM. */ - if (!can_modify_mm(mm, start, end)) + if (unlikely(!can_modify_mm(mm, start, end))) return -EPERM; arch_unmap(mm, start, end); diff --git a/mm/mprotect.c b/mm/mprotect.c index b30b2494bfcd..465c6cd9578c 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -748,7 +748,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, * checking if memory is sealed. * can_modify_mm assumes we have acquired the lock on MM. */ - if (!can_modify_mm(current->mm, start, end)) { + if (unlikely(!can_modify_mm(current->mm, start, end))) { error = -EPERM; goto out; } diff --git a/mm/mremap.c b/mm/mremap.c index d69b438dcf83..223552901f14 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -912,7 +912,7 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len, * * can_modify_mm assumes we have acquired the lock on MM. */ - if (!can_modify_mm(mm, addr, addr + old_len)) + if (unlikely(!can_modify_mm(mm, addr, addr + old_len))) return -EPERM; if (flags & MREMAP_FIXED) { @@ -1087,7 +1087,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, * Place can_modify_mm here so we can keep the logic related to * shrink/expand together. */ - if (!can_modify_mm(mm, addr, addr + old_len)) { + if (unlikely(!can_modify_mm(mm, addr, addr + old_len))) { ret = -EPERM; goto out; } diff --git a/mm/mseal.c b/mm/mseal.c index daadac4b8125..bf783bba8ed0 100644 --- a/mm/mseal.c +++ b/mm/mseal.c @@ -32,7 +32,7 @@ static inline void set_vma_sealed(struct vm_area_struct *vma) */ static bool can_modify_vma(struct vm_area_struct *vma) { - if (vma_is_sealed(vma)) + if (unlikely(vma_is_sealed(vma))) return false; return true; @@ -75,7 +75,7 @@ bool can_modify_mm(struct mm_struct *mm, unsigned long start, unsigned long end) /* going through each vma to check. */ for_each_vma_range(vmi, vma, end) { - if (!can_modify_vma(vma)) + if (unlikely(!can_modify_vma(vma))) return false; } @@ -100,7 +100,7 @@ bool can_modify_mm_madv(struct mm_struct *mm, unsigned long start, unsigned long /* going through each vma to check. */ for_each_vma_range(vmi, vma, end) - if (is_ro_anon(vma) && !can_modify_vma(vma)) + if (unlikely(is_ro_anon(vma) && !can_modify_vma(vma))) return false; /* Allow by default. */