From patchwork Tue Jul 11 04:57:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nick Terrell X-Patchwork-Id: 9834077 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 E526B602A0 for ; Tue, 11 Jul 2017 04:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E426928450 for ; Tue, 11 Jul 2017 04:58:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D81BE28590; Tue, 11 Jul 2017 04:58:57 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 72F2128450 for ; Tue, 11 Jul 2017 04:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751270AbdGKE6W (ORCPT ); Tue, 11 Jul 2017 00:58:22 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:49701 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbdGKE6U (ORCPT ); Tue, 11 Jul 2017 00:58:20 -0400 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v6B4vltZ017837; Mon, 10 Jul 2017 21:58:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=cL1ICd7Yv1RzNbiNwApVGyzMUXkSZ5jy1AYFhmZJPwk=; b=cMFzH9ASdAU+OZxvUFnjVnTXmfcJouLBYm+Z4cs6MIkBk6HZBmNSTWYGI4rH9sdaFsZz ybvO3aTeuIgBotpMxh+AOPNIXvI8396cWxl2zVPdxLYU9mp6Paz6QPwnkmL6xOz/HVnT r4+3i9q9UJctuCcsFRktzt60xRdg4dir12Y= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2bmfcghdp0-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 10 Jul 2017 21:58:09 -0700 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.11) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 10 Jul 2017 21:58:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector1-fb-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=cL1ICd7Yv1RzNbiNwApVGyzMUXkSZ5jy1AYFhmZJPwk=; b=c/36xYsOqb3NDdqR6VGNl1mIIId5WYDJkJ0ALSSPPtuLR9Qr6eiTs+92JNfogwuPyUZgcsOuQ3rQwF6geJfPvo+E9ONPxVJQ2buQx42VUUxgI6yIJEYyGpg/VZojDMBCYkJeyuV2oVPj2GNcgbYsO7R3KyKISUc3CJdQGNF1lh4= Received: from DM5PR15MB1753.namprd15.prod.outlook.com (10.174.246.135) by DM5PR15MB1212.namprd15.prod.outlook.com (10.173.209.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1240.13; Tue, 11 Jul 2017 04:57:50 +0000 Received: from DM5PR15MB1753.namprd15.prod.outlook.com ([10.174.246.135]) by DM5PR15MB1753.namprd15.prod.outlook.com ([10.174.246.135]) with mapi id 15.01.1240.020; Tue, 11 Jul 2017 04:57:50 +0000 From: Nick Terrell To: "Austin S. Hemmelgarn" , Adam Borowski CC: Kernel Team , Chris Mason , Yann Collet , David Sterba , "linux-btrfs@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2 3/4] btrfs: Add zstd support Thread-Topic: [PATCH v2 3/4] btrfs: Add zstd support Thread-Index: AQHS8Q/LbUGGKKAiq0CVg+3Wq3AYu6JHCMaAgAGOPwCAAHujAIAAOccAgAPD0QCAAJzEgA== Date: Tue, 11 Jul 2017 04:57:50 +0000 Message-ID: <15FC42E2-5823-4AF4-A945-0F7C60E7751C@fb.com> References: <20170629194108.1674498-1-terrelln@fb.com> <20170629194108.1674498-4-terrelln@fb.com> <20170706163225.xbluc2gi2nlaafzo@angband.pl> <20170707234018.syyfaktjxyxvwglc@angband.pl> <20170708030706.tle2mpfe376jneft@angband.pl> <046c7611-be6d-ec4d-6489-e8f49a4453f6@gmail.com> In-Reply-To: <046c7611-be6d-ec4d-6489-e8f49a4453f6@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [2620:10d:c090:200::7:776c] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DM5PR15MB1212; 20:1vJTBlubBG8gyV9Ws5P68n4orwlRyqxmnaPUO7EcD8sj1KNxH6WSWm+FkSoDN4xmKIMtMcZVr2h2IX/pjIsmOAQSNZvmVWiHX44C6i7/x4NzCObhyeQg2GkzeGnw9Xn6XagRVlBJ0qhgUrcC53qxdx8T19nxbue8vW8PoG3asMo= x-ms-office365-filtering-correlation-id: f39e31da-6134-403f-205e-08d4c8196199 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(300000503095)(300135400095)(2017052603031)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM5PR15MB1212; x-ms-traffictypediagnostic: DM5PR15MB1212: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(133145235818549)(22074186197030)(236129657087228)(67672495146484)(48057245064654)(183786458502308); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(2017060910075)(10201501046)(93006095)(93001095)(3002001)(100000703101)(100105400095)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123558100)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR15MB1212; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM5PR15MB1212; x-forefront-prvs: 0365C0E14B x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(39410400002)(39840400002)(39450400003)(39400400002)(39850400002)(51914003)(24454002)(377424004)(377454003)(39060400002)(77096006)(6506006)(966005)(93886004)(25786009)(102836003)(14454004)(33656002)(6116002)(76176999)(54356999)(2950100002)(6486002)(6436002)(4326008)(50986999)(478600001)(36756003)(229853002)(2906002)(7736002)(3660700001)(189998001)(3280700002)(53546010)(8936002)(6246003)(5660300001)(99286003)(305945005)(6512007)(6306002)(81166006)(86362001)(54906002)(83716003)(38730400002)(2900100001)(53936002)(82746002)(8676002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR15MB1212; H:DM5PR15MB1753.namprd15.prod.outlook.com; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; received-spf: None (protection.outlook.com: fb.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: <6BA61D6114682F4A944144A27B5E6795@namprd15.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jul 2017 04:57:50.1995 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR15MB1212 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-11_02:, , signatures=0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 7/10/17, 5:36 AM, "Austin S. Hemmelgarn" wrote: > On 2017-07-07 23:07, Adam Borowski wrote: >> On Sat, Jul 08, 2017 at 01:40:18AM +0200, Adam Borowski wrote: >>> On Fri, Jul 07, 2017 at 11:17:49PM +0000, Nick Terrell wrote: >>>> On 7/6/17, 9:32 AM, "Adam Borowski" wrote: >>>>> Got a reproducible crash on amd64: >>> >>>> Thanks for the bug report Adam! I'm looking into the failure, and haven't >>>> been able to reproduce it yet. I've built my kernel from your tree, and >>>> I ran your script with the kernel.tar tarball 100 times, but haven't gotten >>>> a failure yet. >>> >>>> I have a few questions to guide my debugging. >>>> >>>> - How many cores are you running with? I’ve run the script with 1, 2, and 4 cores. >>>> - Which version of gcc are you using to compile the kernel? I’m using gcc-6.2.0-5ubuntu12. >>>> - Are the failures always in exactly the same place, and does it fail 100% >>>> of the time or just regularly? >>> >>> 6 cores -- all on bare metal. gcc-7.1.0-9. >>> Lemme try with gcc-6, a different config or in a VM. >> >> I've tried the following: >> * gcc-6, defconfig (+btrfs obviously) >> * gcc-7, defconfig >> * gcc-6, my regular config >> * gcc-7, my regular config >> * gcc-7, debug + UBSAN + etc >> * gcc-7, defconfig, qemu-kvm with only 1 core >> >> Every build with gcc-7 reproduces the crash, every with gcc-6 does not. >> > Got a GCC7 tool-chain built, and I can confirm this here too, tested > with various numbers of cores ranging from 1-32 in a QEMU+KVM VM, with > various combinations of debug options and other config switches. The problem is caused by a gcc-7 bug [1]. It miscompiles ZSTD_wildcopy(void *dst, void const *src, ptrdiff_t len) when len is 0. It only happens when it can't analyze ZSTD_copy8(), which is the case in the kernel, because memcpy() is implemented with inline assembly. The generated code is slow anyways, so I propose this workaround, which will be included in the next patch set. I've confirmed that it fixes the bug for me. This alternative implementation is also 10-20x faster, and compiles to the same x86 assembly as the original ZSTD_wildcopy() with the userland memcpy() implementation [2]. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81388#add_comment [2] https://godbolt.org/g/q5YpLx Signed-off-by: Nick Terrell --- lib/zstd/zstd_internal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.9.3 diff --git a/lib/zstd/zstd_internal.h b/lib/zstd/zstd_internal.h index 6748719..ade0365 100644 --- a/lib/zstd/zstd_internal.h +++ b/lib/zstd/zstd_internal.h @@ -126,7 +126,9 @@ static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG; /*-******************************************* * Shared functions to include for inlining *********************************************/ -static void ZSTD_copy8(void *dst, const void *src) { memcpy(dst, src, 8); } +static void ZSTD_copy8(void *dst, const void *src) { + ZSTD_write64(dst, ZSTD_read64(src)); +} #define COPY8(d, s) \ { \ ZSTD_copy8(d, s); \