From patchwork Fri Jun 2 03:33:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Miller X-Patchwork-Id: 9761505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 29B4A60365 for ; Fri, 2 Jun 2017 03:33:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03AFD2018E for ; Fri, 2 Jun 2017 03:33:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB1B22855A; Fri, 2 Jun 2017 03:33:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E2552018E for ; Fri, 2 Jun 2017 03:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751122AbdFBDde (ORCPT ); Thu, 1 Jun 2017 23:33:34 -0400 Received: from shards.monkeyblade.net ([184.105.139.130]:36084 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751120AbdFBDdd (ORCPT ); Thu, 1 Jun 2017 23:33:33 -0400 Received: from localhost (cpe-66-108-81-97.nyc.res.rr.com [66.108.81.97]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) (Authenticated sender: davem-davemloft) by shards.monkeyblade.net (Postfix) with ESMTPSA id 7B11312366F88; Thu, 1 Jun 2017 19:51:55 -0700 (PDT) Date: Thu, 01 Jun 2017 23:33:29 -0400 (EDT) Message-Id: <20170601.233329.698047529665811283.davem@davemloft.net> To: sandeen@sandeen.net Cc: matorola@gmail.com, sparclinux@vger.kernel.org, linux-xfs@vger.kernel.org Subject: Re: [sparc64] crc32c misbehave From: David Miller In-Reply-To: <9902b59c-0f73-f306-28e0-fea7ee4a1169@sandeen.net> References: <20170601.174419.2151404855471358626.davem@davemloft.net> <20170601.215711.1719799806113363582.davem@davemloft.net> <9902b59c-0f73-f306-28e0-fea7ee4a1169@sandeen.net> X-Mailer: Mew version 6.7 on Emacs 25.2 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Thu, 01 Jun 2017 19:51:55 -0700 (PDT) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Sandeen Date: Thu, 1 Jun 2017 21:10:50 -0500 > On ARM, there was a gcc bug causing similar results - I /think/ > it was https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293 > > "programs could fail sporadically with this if an interrupt happens at > the wrong instant in time and data was written onto the current stack." > > https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02292.html > > Maybe totally unrelated; if not, hope it helps. :) Wow, that looks exactly like what the bug is: crc32c: .register %g2, #scratch save %sp, -176, %sp ! sethi %hi(tfm), %g1 !, tmp121 mov %i2, %o2 ! length, ldx [%g1+%lo(tfm)], %g2 ! tfm, tfm.0_4 mov %i1, %o1 ! address, lduw [%g2], %g1 ! tfm.0_4->descsize, tfm.0_4->descsize add %g1, 38, %g1 ! tfm.0_4->descsize,, tmp126 srlx %g1, 4, %g1 ! tmp126,, tmp127 sllx %g1, 4, %g1 ! tmp127,, tmp128 sub %sp, %g1, %sp !, tmp128, add %sp, 2230, %i5 !,, tmp130 Ok, %i5 holds the stack address of the shash context: ... return %i7+8 lduw [%o5+16], %o0 ! MEM[(u32 *)__shash_desc.1_10 + 16B], 'return' deallocates the stack frame plus the register window, and at the same time does a delayed control transfer to "%i7 + 8". So in the branch delay slot instruction %i5 becomes %o5. And here we are accessing deallocated stack memory in the delay slot. I'm using gcc-6.3.0 here. And indeed the following patch makes the problem go away: --- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/lib/libcrc32c.c b/lib/libcrc32c.c index 74a54b7..bf831e2 100644 --- a/lib/libcrc32c.c +++ b/lib/libcrc32c.c @@ -43,7 +43,7 @@ static struct crypto_shash *tfm; u32 crc32c(u32 crc, const void *address, unsigned int length) { SHASH_DESC_ON_STACK(shash, tfm); - u32 *ctx = (u32 *)shash_desc_ctx(shash); + u32 ret, *ctx = (u32 *)shash_desc_ctx(shash); int err; shash->tfm = tfm; @@ -53,7 +53,9 @@ u32 crc32c(u32 crc, const void *address, unsigned int length) err = crypto_shash_update(shash, address, length); BUG_ON(err); - return *ctx; + ret = *ctx; + barrier(); + return ret; } EXPORT_SYMBOL(crc32c);