From patchwork Wed Oct 4 16:53:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13409068 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 9C72DE7C4E2 for ; Wed, 4 Oct 2023 16:53:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 989FB6B026F; Wed, 4 Oct 2023 12:53:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A2176B0273; Wed, 4 Oct 2023 12:53:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DD1F6B0274; Wed, 4 Oct 2023 12:53:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1D0D86B0272 for ; Wed, 4 Oct 2023 12:53:25 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EBE11A0391 for ; Wed, 4 Oct 2023 16:53:24 +0000 (UTC) X-FDA: 81308374728.17.E6EA004 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id 48C9A1C001F for ; Wed, 4 Oct 2023 16:53:23 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LRSyEDwt; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696438403; 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=vWwsy+BgXOEcfKuqkIEkXjDw+riS2szWYiR2hDnP9b4=; b=2go1D62bftfp256tuXzsR8Jr+c4WJedjpiHLKr/Sx4hJjJ6N8VvPyXxLNtvj8gPvhsaR6Q z8VDE2jMhjfUpl8tcAe1rjbsPaaumr7JRFy2UIZ/8t9Z5tpkL0Y+Ea+qvOwChESrS09VQt 4Wa5RuoSOkDNRjfpOh3KF7hPW9ITHlc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696438403; a=rsa-sha256; cv=none; b=tR+d4GxUuQ0Gi2ZhwT0whEiHcbFMLjm/5QCtZ57sWH6LfEvmOfW9lubRlIUXUVxBcN6swL sEy5iOyv1L7OK1riF+m0kTW7YG7s3Wfb8bXaPGk80W5uGJUUjO/pc9coaOXszAZS7KZad2 4HSYovXdAnZrss3h0rFsp1lGKZ8hHNA= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LRSyEDwt; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=vWwsy+BgXOEcfKuqkIEkXjDw+riS2szWYiR2hDnP9b4=; b=LRSyEDwtmAXo0SM67p0C/noFmS iQRqwWT0ozrzzklRbep0Y8uPDstZQyqeEmgSEyRLFrVaMAAHGAi6KuiXuL7rxIpp9Wy70RMINXlAc zMlCgxVoBipZVAADPqwuURev5kaILMLePvWQRxlX0JOeMyGqz51FeD55M+cMEekRpNkbU5OhH5Pj9 W3/ibRKkViqP8KeDxEoR6lj+8CrmlJY/CGvO4/2DwLzgk33nshJZZ5xFeCpgyIFC7cP6whN+rIPCb 32UOsNltjlEo+FKhHJ3Ip0qXuHp6b+Nf9dJ3ITrnJDIiNYspgFlpByG8RcOATrn60yzanbbajMwd9 9shECiMw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qo57g-004SFV-1h; Wed, 04 Oct 2023 16:53:20 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, torvalds@linux-foundation.org, npiggin@gmail.com Subject: [PATCH v2 10/17] mips: Implement xor_unlock_is_negative_byte Date: Wed, 4 Oct 2023 17:53:10 +0100 Message-Id: <20231004165317.1061855-11-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231004165317.1061855-1-willy@infradead.org> References: <20231004165317.1061855-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 48C9A1C001F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: z4rw5ow189rd6d9ap1631pk47yjhjsxf X-HE-Tag: 1696438403-814850 X-HE-Meta: U2FsdGVkX1++2MgNFpc7m8dzG7jQuJVMZR35JXZnvyaO4HBLtBfk9BkYBAlYs6ukS7gUNeOFnPIUCupczhZB+IqqUk5bswmY57ig1CKBcG5dcpU8bmYC2xWWD7PEwufAX7tcrBcx1We16PlN0+9evX82LlMzmN/6bEuAu8knk3jy+alppSerkQ7TN5qG4jN2SbDFqTvPUtxP4wSRH97z1llElZseN6fq988z/IOXysZobI3q1Hs5Pv+f/tnmAnBvtx+3UJcq/0uKVweZFFLPdzu9jp5l7tbclaqfCZnMA02Rz+WaOyKDibLoD4u/lDzEyZi/THxy3lpi1v97kGF6i9DLtLxQFN+oJmLifSEbH7uzBFeu/IecnU/cpLtuYClN2h7EP6cOSE/dfoAvzSavLuxhp04yXoHVB5d1comuIgO9GK94SMeRykTlJ0cv4jDRzqjbutxOr++JaLO80yUpLPz1t/+wpJhLmiAK4p4Dc130k/nYfqW+oh3IAWiuURzgWDin2K0Y2Vu61HyIeVir1cxxpMoQ7pRg0s2rT79KFlpavSjPMFjCgzNxwS/GmOG4R2qaastlSrP2VZwSHXxhIUPUx8smK7zRsfkaHl/Bjd++KUejpJPFJ9Ok4wsccK3MUWoZYpvftDDlmRboy1AkUa9Dt91eAVsUB7iitvMDii8c0zfuQOugAgPrNAz2JEs7JLqx+KX6HJDitZJuZfypkZATh1m/LqMbyiJCXpM0EVQ18RczdG5xRlbXgkVpmLNwiTb9aQvJ9oxc0DccV0nFHAsdSyXeiIlaEw7vZDHu3x0pGQjpq8rlRsloxj4ntnrkxWzPftS2bGmrkDU5Xh4nte40l2lOh2XwitJcyCmG+I01dcj2QU/WPWRNwBg2f1MpVBmYu8GjHVcOQ0bl2+G21arGw1TYq03O2t/WC8FxzQExBed2KgvODOX+XEIh0BKIjI9zeqG9d1YzaH11c9S YAMW+CsB X3TwSIF3NpKXm97axjBy7asN1dRKA46Bauc5CQO/DTdCpinsIhrEeXcRVyc6cH0WRohH1U79DmgaVGuygSZcYe30ZVtOH83FFfikllybe88WW1DecKuHfZheQypKOuptzcxU2aGvcwmbjB+kwxZ2w6CnL31dgVyfeTtJfHRnaEfCh3nfaNGRuRTmGhwotxRcDY/elEmPP8IvuYHuWKWldn6Ty6fTpHm+RGmVs 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: Inspired by the mips test_and_change_bit(), this will surely be more efficient than the generic one defined in filemap.c Signed-off-by: Matthew Wilcox (Oracle) --- arch/mips/include/asm/bitops.h | 26 +++++++++++++++++++++++++- arch/mips/lib/bitops.c | 14 ++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/arch/mips/include/asm/bitops.h b/arch/mips/include/asm/bitops.h index b4bf754f7db3..d98a05c478f4 100644 --- a/arch/mips/include/asm/bitops.h +++ b/arch/mips/include/asm/bitops.h @@ -73,7 +73,8 @@ int __mips_test_and_clear_bit(unsigned long nr, volatile unsigned long *addr); int __mips_test_and_change_bit(unsigned long nr, volatile unsigned long *addr); - +bool __mips_xor_is_negative_byte(unsigned long mask, + volatile unsigned long *addr); /* * set_bit - Atomically set a bit in memory @@ -279,6 +280,29 @@ static inline int test_and_change_bit(unsigned long nr, return res; } +static inline bool xor_unlock_is_negative_byte(unsigned long mask, + volatile unsigned long *p) +{ + unsigned long orig; + bool res; + + smp_mb__before_atomic(); + + if (!kernel_uses_llsc) { + res = __mips_xor_is_negative_byte(mask, p); + } else { + orig = __test_bit_op(*p, "%0", + "xor\t%1, %0, %3", + "ir"(mask)); + res = (orig & BIT(7)) != 0; + } + + smp_llsc_mb(); + + return res; +} +#define xor_unlock_is_negative_byte xor_unlock_is_negative_byte + #undef __bit_op #undef __test_bit_op diff --git a/arch/mips/lib/bitops.c b/arch/mips/lib/bitops.c index 116d0bd8b2ae..00aee98e9d54 100644 --- a/arch/mips/lib/bitops.c +++ b/arch/mips/lib/bitops.c @@ -146,3 +146,17 @@ int __mips_test_and_change_bit(unsigned long nr, volatile unsigned long *addr) return res; } EXPORT_SYMBOL(__mips_test_and_change_bit); + +bool __mips_xor_is_negative_byte(unsigned long mask, + volatile unsigned long *addr) +{ + unsigned long flags; + unsigned long data; + + raw_local_irq_save(flags); + data = *addr; + *addr = data ^ mask; + raw_local_irq_restore(flags); + + return (data & BIT(7)) != 0; +}