From patchwork Fri May 31 09:16:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiapeng Chong X-Patchwork-Id: 13681396 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 4F0DEC25B75 for ; Fri, 31 May 2024 09:16:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D76756B0088; Fri, 31 May 2024 05:16:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CFF406B0092; Fri, 31 May 2024 05:16:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC7186B0093; Fri, 31 May 2024 05:16:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9AB9F6B0088 for ; Fri, 31 May 2024 05:16:58 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3CA3E1A0B9B for ; Fri, 31 May 2024 09:16:58 +0000 (UTC) X-FDA: 82178136516.16.9B4AAF8 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by imf11.hostedemail.com (Postfix) with ESMTP id 870024000E for ; Fri, 31 May 2024 09:16:55 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Q9wU3dHf; spf=pass (imf11.hostedemail.com: domain of jiapeng.chong@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=jiapeng.chong@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717147016; 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:references:dkim-signature; bh=QxHkEYftDlz/KeEpN4FX7pbniR6z89NxwWd3eLvuSoc=; b=HZlK0w8DdA+DcvPLixENIN085qRSo47es7/n8dsur1EGIK+S7YikSqvSmdzwZaA58PQOu3 4dBxp0hQkrurzuMt2Pk3YxsmVdHpIUHOKfu+8PlIClmxvPpGfq6+y18kKZt7JTmy3El2Yj OCHyibzJo4ojkppOgG36GVkHrlJdSLU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=Q9wU3dHf; spf=pass (imf11.hostedemail.com: domain of jiapeng.chong@linux.alibaba.com designates 115.124.30.113 as permitted sender) smtp.mailfrom=jiapeng.chong@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717147016; a=rsa-sha256; cv=none; b=TQxakxr2LimZMPIDKJDX2hhv0PN1+Xn+LtsTDF5Hu66gkpGzLb/IAJSPaILfIpwPQQuj0A +OXomATDdWkqFWSpaUcv14JQ65A1qrVXUMqQkjY64tODouRgcgrtpcbfNX4/VBaOeGCZgT dkSMkampXb1JjUpK3bQo36OOe7tMMxs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717147012; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=QxHkEYftDlz/KeEpN4FX7pbniR6z89NxwWd3eLvuSoc=; b=Q9wU3dHf+tdA/dZt+i0IhlHCuem5FtuFhmITSD7+TojUK1PKjPFdV41QBTUNKzU8AHcXGRu2IOl/2Ohxs2kcFlR/oNyxwLT7eMyuxrDKLVYoSsAo5uY1V4H+Elv7+ccw/+lsMAoW//radMx4FiFlR12rUYBNiYt8S21Ge5qblIU= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033037067109;MF=jiapeng.chong@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0W7ZLw8K_1717147005; Received: from localhost(mailfrom:jiapeng.chong@linux.alibaba.com fp:SMTPD_---0W7ZLw8K_1717147005) by smtp.aliyun-inc.com; Fri, 31 May 2024 17:16:51 +0800 From: Jiapeng Chong To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jiapeng Chong , Abaci Robot Subject: [PATCH] mm: userfaultfd: Use swap() in double_pt_lock() Date: Fri, 31 May 2024 17:16:43 +0800 Message-Id: <20240531091643.67778-1-jiapeng.chong@linux.alibaba.com> X-Mailer: git-send-email 2.20.1.7.g153144c MIME-Version: 1.0 X-Stat-Signature: fg3r8z64go9dyoj69c5yr889zx86tf1h X-Rspamd-Queue-Id: 870024000E X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1717147015-768511 X-HE-Meta: U2FsdGVkX1+zSNqe7AJkE22kCsfNkVBWifMO5hf1dEfBKhMOHWXjykpxVIiEMx497y1A4bXCvJzPNKnShesEpmb5xIRJk+5jv9OaaoIuvQ1jQ7GVJrvPrxlcwSQngR6f4kOa2x7ZCPGg66eGvr1XE3yiByV0wSwO3JligzOqtz+w25XIkM2fNC1VMRxuiNYRGyNBQ+S5JPtGRHfl/8NURi1FmV9Jd8cch9t6/wC2x24ZfFOT7pq/5p+69wM1aFqfHlboOZQvfHR6SprtXVak1NgZrEd+Di7nb5y7r9iKM5lkJ78/8lPvN6iAZLgU66R5nVXN9TQT2FI8xUxT5LTPkYq7qYs4jQkP9bggfW5pLU+vbX3DHWgLmIIhgAWI79ksAjHGT2LD7u0+fuTqPti08Ghz6N/9Dsxc2Ghag9FfNo5SyoKMV9rV7pwUylAfWcPzQRkzB8AzTopQBpHyhYxJmFAj1+3Qxb4yfqVVidrKdGJrwu7CO0xncqTHnvmj98lDABIkHt9V/IZ4BxVRCiP6ClK3j4iVVH4BvwIPkB5aAl2rOi1CTj1BsS5sfoQ3m/vUpEyWqtTPZvgrDxntgNBuGsPEugkfiYr02/wtDgRk9f6i7YF/uJoJJLazMzd+vPi5kWzKdoseJFf+tLEfyYzC1FStx0GZyq4elSEVWljvxVQwB3Ll7974MFTNpKo5dWutkMXjiupSwTy5lrWa/Jg/bT5LyHJEV8wNkTHajWyHZkHLy/pc1x/n3ylga/gj8lucqv4M+0o8LrnMnJSYdwfEJlxQwwVDrJ+3B1p55ytJxpQSOSspVKKnXOwLWPIwCUBWQxg7N8ksJxLeuz49wu3xWwBQ2VTzJ4qRC6RD5FYIvQHu4gcAk3mbVh9mq75gg7TsiGWSAX2tC/jmpKOp/kFaHfib7iWgsnHqnJy8qUiTQori19LUKaLTl0zYLer7zQlEfHfD9WVe9StM5fkpU+K VaIlLheQ VqFL/rYiXlp8vg8OCop9NKfO5DhHVbpy5/aUHdWNteambr4sDNqaNECz3g+/8M2cR5Lz2CbE21QIupwOP1T6r/YeMNqe+S/BuWUwkbXsrR3jyo8r5GDKOe6XpEcw8JpRyn8H93lR7DcnpKwcmdYpkroVZQiUwvaMr+yrpMY+QZ9f8BpOErkEiyue7v3n3MdYHTzNsMs/x2mW2D3fwVLccrmGDAd6CaKe5pcmpO+jYE/ZkDxizIobkGsBC9ZuBzZnaqsyUKSsHTRWITEOKDeHJO2XbSQuQ3nBQlsvw8rfZm1nz7y6nPICyJ91jZzGVCnXUKJiSSfH+lclrq0XAdERpskMmZq5e3X8afGtE5+l4NTCnouE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.008031, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use existing swap() function rather than duplicating its implementation. ./mm/userfaultfd.c:1006:13-14: WARNING opportunity for swap() Reported-by: Abaci Robot Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=9266 Signed-off-by: Jiapeng Chong Reviewed-by: David Hildenbrand --- mm/userfaultfd.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index defa5109cc62..5e7f2801698a 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -995,14 +995,8 @@ void double_pt_lock(spinlock_t *ptl1, __acquires(ptl1) __acquires(ptl2) { - spinlock_t *ptl_tmp; - - if (ptl1 > ptl2) { - /* exchange ptl1 and ptl2 */ - ptl_tmp = ptl1; - ptl1 = ptl2; - ptl2 = ptl_tmp; - } + if (ptl1 > ptl2) + swap(ptl1, ptl2); /* lock in virtual address order to avoid lock inversion */ spin_lock(ptl1); if (ptl1 != ptl2)