Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5075231rdb; Sat, 16 Sep 2023 01:40:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw4DgrveMzZZ95MkHtF55FOryBcK4/LuVKRNE5gKRiugdmkqXaV+o3tYvSRd75rkgWPsZ9 X-Received: by 2002:a05:620a:c4f:b0:76d:2725:f36f with SMTP id u15-20020a05620a0c4f00b0076d2725f36fmr4264472qki.71.1694853612487; Sat, 16 Sep 2023 01:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694853612; cv=none; d=google.com; s=arc-20160816; b=PsPGAT/c5OcGG7YC7uGn8v5sC311k1l8m+4EFF8lvOywcmFvRN3u2BHj4bzwy3rojt PcrlEhuzBSh94UL2hYIGCY8cltjeDqIRJ+3YgJ84l0iEloyl/Q5IdsfR0GqgoSap+hlr 4szI81ih4T2ZGgtTLDLCQN9SWS+n5rV0s7t5CA1HHyHxXFZjnDna2ZMYxqY4oYpO7WrW NdPYpqRnyWYlzP6/6xQHqtPrTQZPH13BoF/SUI7hW+ZwQ0cHIVGyE1ChRCvpmnij6HTs e+YwZRaO91Hv1T+qUBobXCNAePGE1NP9dJrS6LfsWrbZk4GT8zqHCIUpHb7vOXBkjsOu LfdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vWwsy+BgXOEcfKuqkIEkXjDw+riS2szWYiR2hDnP9b4=; fh=Exu8p2J0bt/MoYkEByA/Woj5EWTdUoRsvJYmK88z1hY=; b=CzMLseClqnIwK4JnqiP0e9ms1iKoioobvDCh3n7lQeI5vbb8fBeEgvwQzeLSIS9wMM FZv8TZllKqeoJQA9YA/xTPI5qyQChzkiOQOhjAmY6iDbSUmI1x17WGGieMZhUS8IFGQP pX4bbu56XHFlc3JQ2OngTok5Rp2XiuCILC+e6KEi2oKB6Lse6s96qtdVl89jGYdJW8lY LXj2iWEYvSf6SwaVQ/UmmrM1yVR7219ye6BIOUjl3AgM+CuU+iqr7yzUKpQsfOd5NpNd DP0Nx+QsXlFf4beZr5Fs7GcEq9MJs8j1bZFfaMIM3hQ4hln62/Mo4rNReVphhbikAZnO VO8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iaE2slop; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id k64-20020a638443000000b00573f7ef60aasi4473907pgd.295.2023.09.16.01.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 01:40:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=iaE2slop; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DC3AD80218A4; Fri, 15 Sep 2023 11:38:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236691AbjIOSiF (ORCPT + 99 others); Fri, 15 Sep 2023 14:38:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236596AbjIOShY (ORCPT ); Fri, 15 Sep 2023 14:37:24 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C6D196; Fri, 15 Sep 2023 11:37:18 -0700 (PDT) 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=iaE2slop4N4xLJSD+OgbNbmYDB gvFtf3rpiE7MHfx1VcIaaTK6mqcWPzGB45tY/We9XP2f0KJYV6gGKzvmGnaGt2e4dMZjvKt6U+qoZ WsFrvPotolFPbFSAus8TnTLqvsp79DzGWxNd6OPiUC0zBFJ8QqtYxPBpgfsmB7lLCeWKcELGjqU3R SI2HI870LgmTnj0NvcJMVY/Ff+qZeSlET7hIisVQBmwZejpdiwpNCHb2wohJKyFAUerGvW1W2rtzt QQhq6L1YGWcKYaWuTaIaXH7nHZkN9TozL0NTGQj9pBBGGCg5ZFFmlcZipxMpNs2sZyXo59jSYV1fQ U35De4qQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qhDgj-00BMIn-Rw; Fri, 15 Sep 2023 18:37:09 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, torvalds@linux-foundation.org, Nicholas Piggin Subject: [PATCH 10/17] mips: Implement xor_unlock_is_negative_byte Date: Fri, 15 Sep 2023 19:37:00 +0100 Message-Id: <20230915183707.2707298-11-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230915183707.2707298-1-willy@infradead.org> References: <20230915183707.2707298-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 15 Sep 2023 11:38:27 -0700 (PDT) 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; +} -- 2.40.1